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: [ @pnp/sp: ^1.2.1 ]
Please specify what version(s) of SharePoint you are targeting: [ online ]
i am creating an spfx application that creates a list, adding columns to it thend adding the columns to the default view.
here is my code to create the fields:
public createListFields(listname: string): Promise<any>{
return Promise.all([
sp.web.lists.getByTitle(this.listName).fields.addMultilineText("Questions",6,false,false,false,false),
sp.web.lists.getByTitle(this.listName).fields.addMultilineText("Answers",5,false,false,false,false),
sp.web.lists.getByTitle(this.listName).fields.addChoice("Classification",["Public", "Staff", "Student"],6,true),
sp.web.lists.getByTitle(this.listName).fields.addText("QnAID",255),
sp.web.lists.getByTitle(this.listName).fields.addMultilineText("Remarks",5,false,false,false,false)
]).then(res => {
return res;
}, (error: any) => {
return error;
}).catch(err => {
return err;
});
}
but i am having errors such as:
The specified program requires a newer version of Windows. (Exception from HRESULT: 0x8007047E)
and
Save Conflict.\n\nYour changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes."
is there a proper way to add fields to the list?
this is also how i add fields to the view:
public addFieldsToView(listname: string): Promise<any>{ //, fieldsToAdd: any[]
return Promise.all([
sp.web.lists.getByTitle(listname).defaultView.fields.add("Questions"),
sp.web.lists.getByTitle(listname).defaultView.fields.add("Answers"),
sp.web.lists.getByTitle(listname).defaultView.fields.add("Classification"),
sp.web.lists.getByTitle(listname).defaultView.fields.add("QnAID"),
sp.web.lists.getByTitle(listname).defaultView.fields.add("Remarks")
]).then(res => {
return res;
}, (error: any) => {
return error;
}).catch(err => {
return err;
});
}
Thank you for your feedback!
Hi @paigeflourin,
Fields can't be added in parallel, it's API specifics.
You should use sequential calls or batches.
This issue contains the code samples which demonstrates the idea.
Hi @koltyakov ,
thank you very much, i can use the referenced issue for the view fields however for the add list fields, may i just ask one question? what if the fields that i want to add to the list had different data types? is it efficient to run them sequentially right after another?
If it's in a batch, only one physical request is sent and then processed sequentially on the backend.
Sequential calls on the client with async/await in most situations also pretty much efficient as a number of fields which are created is not huge.
Going to close this as answered. Please _reopen_ should the conversation need to continue. Thanks!
Most helpful comment
Hi @paigeflourin,
Fields can't be added in parallel, it's API specifics.
You should use sequential calls or batches.
This issue contains the code samples which demonstrates the idea.