I'm developing a sharepoint hosted Add-in, which should react to a change of a list field of a list in the hostweb. I need some kind of EventListener for a list field.

For example:

List field Gets updated --> DOM object in Add-in should react (not in realtime, but <2-3 seconds would be nice)

Is there any kind of service for this in sharepoint? Or does anyohne have an idea, how this could be solved?

I have no idea how to realize that with the CSOM.


What you are looking for are called "Remote Event Receivers" and they are only available in Provider Hosted Add-Ins (https://msdn.microsoft.com/en-us/library/office/jj220043.aspx.)

Given that SP Hosted Add-Ins can only use javascript that executes in the browser, there is no way to react to an OOTB event such as ItemUpdated.

What you could do is implement a custom form within your add-in that is able to update the appropriate list items in your host web, as well as perform whatever logic is needed while updating those items.

If you want a page or app-part in your add-in to respond to a change in the host web while the page or app part is open in a browser, you could do something like poll the hostweb every few seconds, checking for the change. You may be able to use GetListItemChangesSinceToken https://msdn.microsoft.com/en-us/library/office/dn292554.aspx, or just a simple query to the list. Be careful of querying too often for performance reasons, especially if the target list in the host web is large (>5000 items.)

  • That sounds good. Thanks for your answer! I'll give it a try. – bge Jan 29 '16 at 15:03

As Sean mentioned to use a simple query to the list and since getListItemChangesSinceToken() did not work for me, I came up with the following:

  • query the list with window.setInterval(myFunctionThatTriggersTheQuery(), 10000)
  • The myFunctionThatTriggersTheQuery() function also saves the current time into a variable. I'm using Moment.js with this function: moment().format("YYYY-MM-DDTHH:mm:ss"), this format can be used in a query and Sharepoint compares the values of the desired list field (in my case the 'Modified' field of the list) and the value of the variable
  • Change the CSS on the page in the successHandler method of executeQueryAsync by iterating through the returned collection

and the following query:

    "<View>" +
        "<ViewFields>" +
          "<FieldRef Name='Modified' />" +
        "</ViewFields>" +
      "<Query>" +
        "<Where>" +
          "<Gt>" +
            "<FieldRef Name='Modified'/>" +
              "<Value Type='DateTime' IncludeTimeValue='True'>" + myTimeVariable + "</Value>" +
          "</Gt>" +
        "</Where>" +
      "</Query>" +

It is important to use the IncludeTimeValue='True' attribute if you want the know the change in between seconds/minutes/hours.

I tried this in a List with about 300 items and there where no noticeable perfomance issues. I hope this can help someone :)

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.