2

I am creating a SharePoint provider-hosted App with event receivers to simply update an item in a SharePoint list List1 when adding new item in the list.

My App installation event is firing, but no list event fired when adding an item (SPRemoteEventType.ItemAdding). Please help.

My ProcessEvent Code is here,

  public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
    {
        SPRemoteEventResult result = new SPRemoteEventResult();
        if (properties.EventType == SPRemoteEventType.ItemAdding)
        {
            if (properties.ItemEventProperties.ListTitle == "List1")
            {
                var title = properties.ItemEventProperties.AfterProperties["Title"];
                result.ChangedItemProperties.Add("Title", title + " action by RER");

                result.Status = SPRemoteEventServiceStatus.Continue;
            }
        }

        return result;
    }

Remote event receiver Elements.xml is:

enter image description here

1 Answer 1

1

I have found the solution.
In the app installing event receiver AppEventReceiver.svc you need to add the item events to your custom list List1 .

ProcessEvent in AppEventReceiver.svc is,

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

        using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false))
        {
            if (clientContext != null)
            {
                var customList = clientContext.Web.Lists.GetByTitle("List1");
                clientContext.Load(clientContext.Web);
                clientContext.ExecuteQuery();

                // debugging url
                //string opContext = OperationContext.Current.Channel.LocalAddress.Uri.AbsoluteUri.Substring(
                //  0, OperationContext.Current.Channel.LocalAddress.Uri.AbsoluteUri.LastIndexOf("/"));

                //string remoteUrl = string.Format("{0}/RemoteEventReceiver1.svc", opContext);

                // deployment
                string remoteUrl = string.Format("https://{0}/RemoteEventReceiver1.svc",
                 OperationContext.Current.Channel.LocalAddress.Uri.DnsSafeHost + "/services");

                EventReceiverDefinitionCreationInformation newEventReceiver = new EventReceiverDefinitionCreationInformation()
                {
                    EventType = EventReceiverType.ItemAdding,
                    ReceiverName = "RemoteEventReceiver1",
                    ReceiverUrl = remoteUrl,
                    SequenceNumber = 1000
                };

                customList.EventReceivers.Add(newEventReceiver);
                clientContext.ExecuteQuery();
            }
        }

        return result;
    }

Now, in RemoteEventReceiver1.svc check the corresponding event type.
ProcessEvent in RemoteEventReceiver1.svc is,

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

        if (properties.EventType == SPRemoteEventType.ItemAdding)
        {
            if (properties.ItemEventProperties.ListTitle == "List1")
            {
                var title = properties.ItemEventProperties.AfterProperties["Title"];
                result.ChangedItemProperties.Add("Title", title + " title changed by RER");

                result.Status = SPRemoteEventServiceStatus.Continue;
            }
        }

        return result;
    }

May be this will help someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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