1

I have developed many server side remote event receivers, but I am new to remote event receivers’ world. Now based on my reading and some tutorials, I find that there are 2 main approaches to create remote event receivers:-

  1. Created a new SP-hosted App >> inside the APP create a new list >> inside the App create a new RER and associated the RER with the new list.

  2. Created a new SP-hosted App >> inside the App create a new RER and associated the RER with a list template (such as custom list).

Now I can understand that the first approach will only force the RER to fire in case the specific list’s items are (added, edited or deleted), while the second approach will be wider as the RER will be associated with all the lists that were created from the specified list templete .

But I have these questions:-

  1. Let say I have an existing list, which I created using the UI. So can I associate a new RER with this list specifically (not to a list template)? or the list need to be created as part of the APP which contain the RER, for the RER to be associated with this list only?

  2. What is better to associated RER to specific list or with specific list template? And when to use each approach?

2

1.

By default we only can select the list instance created in the SharePoint-hosted app when associating the remote event receiver to the list instance. We cannot select the list instance created from the SharePoint UI.

If you want to associate the remote event receiver with list instance created by SharePoint UI, there are two methods:

1.1 Add code to check the list instance

We can create a remote event receiver associated to one list template. And then we can add the code to check if the current list is the list which you want to run the event receiver on. If the list is, then you can add the operations. If the list is not, then return.

public void ProcessOneWayEvent(SPRemoteEventProperties properties)
        {
            using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
            {
                if (clientContext != null)
                {

                    Guid listId = properties.ListEventProperties.ListId;
                    List list = clientContext.Web.Lists.GetById(listId);
                    clientContext.Load(list);
                    clientContext.ExecuteQuery();

                    if(list.Title == "yourlist")
                    {
                        //......
                    }
                    else
                    {
                        return;
                    }
                }
            }
        }

enter image description here

1.2 Edit Element.xml

Edit the Element.xml of the remote event receiver to associate to the list instance created by SharePoint UI.

Replace <Receivers ListTemplateId="100"> with <Receivers ListUrl="Lists/yourlist">.

2.

To associate remote event receiver to specific list template, you could use the second mothed in your post.

To associate remote event receiver to specific list, you could use the above methods as I said. Or you also could use the first method in your post.

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.