0

I have standard js code for update a list on Sharepoint. The problem is that the success function is always triggered even if the update is acctualy failed. The fail function is also triggered but in the second order. What can be reason of this behaviour? This is my update function:

function updateListItem() { 
var WPId = getUrlParameter('WPId');
var server = getUrlParameter('Server');
var webserverrelativeurl = getUrlParameter('Relativeurl');

 // this list doesn't exist
 listTitle = "dsdsdsdsd";
var webUrl = webserverrelativeurl+"/";
var remainingWork = document.getElementById('RemaingWork').value;
var clientContext = new SP.ClientContext(webUrl);
oWeb = clientContext.get_web();
oList = oWeb.get_lists().getByTitle(""+listTitle+"");//Get SPList by     Title
oListItem = oList.getItemById(WPId);
oListItem.set_item(remainingWorkFieldInternalName, remainingWork.toString());
oListItem.update();

clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded_GetData()), 
 Function.createDelegate(this, this.onQueryFailedUpdate)
  );

}

1 Answer 1

4

Remove the () after the success method name in the createDelegate function:

Use

clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded_GetData), 
Function.createDelegate(this, this.onQueryFailedUpdate)
);

instead of

clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded_GetData()), 
Function.createDelegate(this, this.onQueryFailedUpdate)
);
3
  • acctually in the orginal code I also pass some values to this func like that: Function.createDelegate(this, this.onQuerySucceeded_GetData(param1, param2)). Do you realy think this couse the behaviour? Dec 18, 2015 at 14:04
  • 1
    Try using delegate as Robert has said, it is suggested by microsoft too. Please check, msdn.microsoft.com/en-us/library/office/dn168907.aspx Dec 18, 2015 at 14:06
  • Yes I'm sure. You need to use another approach for the parameters (like wrapping in an anonymous function etc Dec 18, 2015 at 14:09

Your Answer

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

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