I am working on remote event receivers, and let say I want to update a field named ProjectID inside my ItemAdded, currently, I am executing a CAML query to get the current item >> update the ProjectID, as follow:-
public void ProcessOneWayEvent(SPRemoteEventProperties properties)
{
var listItemID = properties.ItemEventProperties.ListItemId;
var listTitle = properties.ItemEventProperties.ListTitle;
using (ClientContext context = Helpers.GetAppOnlyContext(properties.ItemEventProperties.WebUrl))
{
CamlQuery camlQuery = new CamlQuery();
context.Load(context.Web);
context.ExecuteQuery();
string webrelativeurl = context.Web.ServerRelativeUrl;
camlQuery.ViewXml = string.Format("<View Scope=\"RecursiveAll\"><Query><Where><Eq><FieldRef Name='ID' /><Value Type='Number'>{0}</Value></Eq></Where></Query></View>", listItemID);
ListItemCollection collListItem = context.Web.GetList(webrelativeurl + "/lists/" + "Projects").GetItems(camlQuery);
context.Load(collListItem, items => items.Include(
item => item.Id,
item => item["ProjectID"],
item => item["ID"],
item => item.RoleAssignments.Include(roleAssigned => roleAssigned.Member.Title, roleAssigned => roleAssigned.RoleDefinitionBindings)
));
context.ExecuteQuery();
//get the template id based on the entered Purpose
foreach (ListItem currentFilingSystemItem in collListItem)
{
ListItemCreationInformation listItemCreationInformation = new ListItemCreationInformation();
ListItem listItem = context.Web.GetList(webrelativeurl + "/lists/" + "Projects").AddItem(listItemCreationInformation);
listItem["ProjectID"] = "ARQ-Project-" + listItem["ID"];
listItem.Update();
So is my approach correct? or I can directly reference the current item instead of getting it by CAML? the issue is that I can not reference properties.ListItem
as in the server-side event receivers.