I've following issue. Function which supopse to create new item on the list, adds the row only when the list is situated in the root node (webUrl = "http://rootserver.com/";) whereas when it is placed in different location the addition doesn't work (webUrl = "http://rootserver.com/cases/SLS/SLS-2015-00003/";). Here is my function.

function createListItem(title,hours,server) {
//var webUrl = "http://rootserver.com/cases/SLS/SLS-2015-00003/";
//var webUrl = "http://rootserver.com/";
var webUrl = server;
var clientContext = new SP.ClientContext(webUrl);
var oList = clientContext.get_web().get_lists().getByTitle('TimeRegistration');

var itemCreateInfo = new SP.ListItemCreationInformation();
this.oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item('Title', title);
oListItem.set_item('Hours', hours);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded_Create), Function.createDelegate(this, this.onQueryFailed)); 

Any ideas why is that?

  • Does the User have the according permissions to alter the list item? Try access via "...../lists/..."
    – Dave
    Dec 15, 2015 at 11:41
  • You mean _api/lists/getbytitle('TimeRegistration')? Yes, I can retrieve the list. Dec 15, 2015 at 11:43
  • hmmm... ok... Is "cases/SLS/SLS-2015-00003/" a subsite or a site collection? If subsite: Try to reduce the path to the actual site collection.
    – Dave
    Dec 15, 2015 at 11:47
  • Yes, it is a subsite. What do you mean 'reduce the path..'? Could you give an example? Dec 15, 2015 at 11:50
  • What errors do you get in the Console? Are really running on http? Dec 15, 2015 at 12:15

1 Answer 1


I am not sure why it works at the root and not at the other location, but I am wondering if it has to do with how you are executing the query. Just before the query you are calling


This is telling the system to go out and get the data from the server, however the data is not yet there. It has been a while since I have written any CSOM code, but I am pretty sure you do not need to load into the context a new item before you execute it because it is already there ready to be executed. What happens if you remove that line? Does it fail utterly or does it make a difference?

  • Well, the whole example is from MSDN page: msdn.microsoft.com/en-us/library/office/jj163201.aspx and there is clientContext.load(oList); directive. I doesnt work either if I remove this line. Dec 15, 2015 at 13:25
  • Yah, it was a shot in the dark. Thanks for letting me know. It was the only thing I could see that (to me) looks possibly out of place. If I think of something else I will come back. Good luck. Dec 15, 2015 at 13:27

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.