0

I created an RER that updates a column when an Item is added, but it is not firing. I added an ItemAdded event and it fired

public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();

            if (properties.EventType == SPRemoteEventType.ItemAdding)
            {
                using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
                {
                    if (clientContext != null)
                    {
                        try
                        {
                            List list = clientContext.Web.Lists.GetByTitle(properties.ItemEventProperties.ListTitle);
                            ListItem listItem = list.GetItemById(properties.ItemEventProperties.ListItemId);

                            listItem["SuccessAdding"] = "Yes Adding 4.0";
                            listItem.Update();
                            clientContext.Load(listItem);
                            clientContext.ExecuteQuery();



                            clientContext.ExecuteQuery();
                        }
                        catch (Exception ex)
                        {

                        }
                    }
                }
            }

            return result;
        }
0

In your code you have checked for the Item Adding in place of Item Added.

Change if (properties.EventType == SPRemoteEventType.ItemAdding) to

if (properties.EventType == SPRemoteEventType.ItemAdded)

And your code will look like below

public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
    {
        SPRemoteEventResult result = new SPRemoteEventResult();

        if (properties.EventType == SPRemoteEventType.ItemAdded)
        {
            using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
            {
                if (clientContext != null)
                {
                    try
                    {
                        List list = clientContext.Web.Lists.GetByTitle(properties.ItemEventProperties.ListTitle);
                        ListItem listItem = list.GetItemById(properties.ItemEventProperties.ListItemId);

                        listItem["SuccessAdding"] = "Yes Adding 4.0";
                        listItem.Update();
                        clientContext.Load(listItem);
                        clientContext.ExecuteQuery();



                        clientContext.ExecuteQuery();
                    }
                    catch (Exception ex)
                    {

                    }
                }
            }
        }

        return result;
    }
  • Well actually I tried ItemAdded and it works fine the difference is that when I use ItemAdded you have to refresh the page to see the result, I want to avoid that, that is why I use ItemAdding – Joshua Dominic Sibug Sep 11 '18 at 6:16
  • As per the question asked and the snippet , provided the solution. However going forward please provide your challenges in the question, that will help other to understand the scenario. – Sunil Sahu Sep 11 '18 at 6:46
0

Suppose you add remote ItemAdding ER to your list by EventReceiverDefinitionCreationInformation, you could use service bus to debug if any exception in your code.

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/debug-and-troubleshoot-a-remote-event-receiver-in-a-sharepoint-add-in

Refere here to create service bus in Azure portal

You could check my sample demo here also, hope it would help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.