Thank you for reporting an issue, suggesting an enhancement, or asking a question. We appreciate your feedback - to help the team understand your
needs please complete the below template to ensure we have the details to help. Thanks!
Please check out the Docs to see if your question is already addressed there. This will help us ensure our documentation covers the most frequent questions.
Please specify what version of the library you are using: 1.1.2
Add a column to a list.
Attempting to add multiple columns to a list in a set of Promise.all() calls, many throw an error - body contents:-
{ error:
{ code: '-2147023746, Microsoft.SharePoint.SPException',
message:
{ lang: 'en-US',
value: 'The specified program requires a newer version of Windows. (Exception from HRESULT: 0x8007047E)' }
}
}
Trying to create columns on a new list:-
retvar.push(sp.web.lists.getById(listID).fields.addText("Department", 255, {
Description: "Department of person making request.",
EnforceUniqueValues: false,
Required: true,
DefaultFormula: ''
}));
return Promise.all(retvar);
I am setting multiple headers as per previous issues found online:-
sp.setup({
sp: {
fetchClientFactory: () => {
return new SPFetchClient(config[rtFlag].siteURL, config[rtFlag].appID, config[rtFlag].appSecret);
},
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"odata-version": "3.0",
"UserAgent": "ISV|OurCompany|ListCreator/1.0"
}
},
});
Hi @pconnell99,
AFAIK, fields can't be added to a list in parallel, I would suggest for/of loops and async/await. There should be no issues in creating multiple list fields.
As mentioned by @koltyakov this is an issue on the server where you are essentially in a race condition. When the two updates hit at the same time one gets through and the other is blocked because the underlying object was updated after the reference was created on the server. I was also able to add multiple fields at once using batching as below:
const web = sp.web;
const batch = web.createBatch();
const list = web.lists.getByTitle("Issue172");
list.fields.inBatch(batch).addText("Text1");
list.fields.inBatch(batch).addText("Text2");
list.fields.inBatch(batch).addText("Text3");
list.fields.inBatch(batch).addText("Text4");
list.fields.inBatch(batch).addText("Text5");
batch.execute().then(_ => console.log("done"));
Going to close this as answered. If you need further assistance on this topic please _reopen_ the issue so we can assist. Thanks!
Happy with close - will pursue batching.
I am trying the above batch update code on my Office 365 Sharepoint it gives me the below error, but strangely it works fine for list value updates in batch mode and field (or column) addition in a non batch mode. Any idea why this is happening ? Thanks
ERROR Error: Uncaught (in promise): Error: Error making HttpClient request in queryable [400] Bad Request ::> {"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"Invalid request."}}}
Error: Error making HttpClient request in queryable [400] Bad Request ::> {"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"Invalid request."}}}
@tarundhillon Have you found a solution?
Most helpful comment
As mentioned by @koltyakov this is an issue on the server where you are essentially in a race condition. When the two updates hit at the same time one gets through and the other is blocked because the underlying object was updated after the reference was created on the server. I was also able to add multiple fields at once using batching as below: