1

Are there any ways to disable event receiver firing by javascript for a list during updating data?

0

Check the below code if it solve your problem.

you want to update the current item metadata or other item metadata in other list or library and also does NOT need to fire another event for the other item you’ve updated.

///
/// Disabled item events scope
/// 
class DisabledItemEventsScope : SPItemEventReceiver, IDisposable
{
   bool oldValue;
   public DisabledItemEventsScope()
   {
      this.oldValue = base.EventFiringEnabled;
      base.EventFiringEnabled = false;
   }
   public void Dispose()
   {
      base.EventFiringEnabled = oldValue;
   }
}

and in your event receiver method ItemAdded, ItemUpdated, or others

public override void ItemUpdated(SPItemEventProperties properties)
{
   base.ItemUpdated(properties);
   SPListItem currItem = properties.ListItem;
   using (DisabledItemEventsScope scope = new DisabledItemEventsScope())
   {
      currItem["Column2"] = "updated";
      currItem.Update();
   }
}

Source https://tjendarta.wordpress.com/2013/10/07/disable-event-firing-in-sharepoint-event-receiver/

  • Thanks for your answering, but what I mean is in javascript (JSOM) – tbbt May 5 '15 at 4:58
0

After reading a few articles I came accross that we cannot do this from Javascript, But there is a workaround, add a column to list to maintain a flag, from javascript code set it as true/ false, you can check this value in Event Receiver and evaluate the code.

JAVASCRIPT CODE

function updateListItem() {
   //your code
    oListItem.set_item('Flag', 'false');
    oListItem.update();
    clientContext.load(oListItem);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
    //your code
}
function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

EVENT RECEIVER CODE

public override void ItemUpdating(SPItemEventProperties properties)
{

   base.ItemUpdated(properties);
  var flag = properties.AfterProperties["Flag"];//get the flag field you set in JSOM
  if(flag is set true)
   {
        //then execute the code in event receiver
   }
}
  • 1
    The workaround you suggested has effect on all the threads changing data in the list. It may be OK, as long the only thread is the one we are executing, but we cannot ensure that. With the same (or less) effort could we de-register, and re-register our event handler as described here: sharepoint.stackexchange.com/questions/45467/…. Of course, this solution requires more permission. – pholpar May 5 '15 at 6:59
  • try setting default value of Flag column to false and make it true when you want to execute the ER, or vice versa may be that can reduce your load – Akshay Randive May 5 '15 at 7:39

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.