1

I want to save multi-select drop-down in SharePoint field. I already referred few results in this site.

Choice values in SharePoint : Test1, Test2, Test3, Test4, Test5.

From the custom drop-down choice field user will select multiple values I want to save the data in multi-select choice field in SharePoint list.

Now am getting results as:

var testvalue="'Test1','Test2'";

$pnp.sp.web.lists.getByTitle("TestList").items.add({
    Testchoicefield:{results:[testvalue]},
    LastModifiedByDisplayName:_DisplayUserName,
    LastModifiedByUserId:_CurrentUserID,
    LastModifiedOn:_modifiedon
}).then(function(resultdata) {
    idvalue = resultdata.data.Id;
    ShowMsgaddupdate("Data Saved Successfully", "", "Ok");

But am not able to save the item. Its throwing error.

Can you please help me?

  • Can you please add an error you are getting in your question? – Ganesh Sanap Aug 13 '19 at 5:25
1

You are passing Choices array in wrong way.

You can create your choices array as given below:

var choicesArray = ["Test1", "Test2"];

Then pass it in the items.add() function as:

$pnp.sp.web.lists.getByTitle("TestList").items.add({
    Testchoicefield: { results: choicesArray },
    LastModifiedByDisplayName: _DisplayUserName,
    LastModifiedByUserId: _CurrentUserID,
    LastModifiedOn: _modifiedon
}).then(function (resultdata) {
    idvalue = resultdata.data.Id;
    ShowMsgaddupdate("Data Saved Successfully", "", "Ok");
});
| improve this answer | |
  • 1
    Hi, does this answers your question? If Yes, please upvote(^) and accept it as an answer. – Ganesh Sanap Aug 23 '19 at 6:43
  • Hi, finally able to test and it doesn't work. I get this error "An unexpected 'StartObject' node was found when reading from the JSON reader. A 'PrimitiveValue' node was expected." This is my code where it's breaking 'Status': { results: that.Status}, – OLA Nov 25 '19 at 18:22
  • Can you share the structure of the that.Status with us? So that we can it is correct or not. It should be a plain array of string. – Ganesh Sanap Nov 26 '19 at 2:32
0

Set multiple value choice field as array like this:

 public render(): void {
        pnp.sp.web.lists.getByTitle("Jerry").items.add({
          Title: "NewAddedTitle",
          MultipleChoice: {
            results: [ 'Enter Choice #1', 'Enter Choice #2' ]
          }
      }).then(result => {
        console.log(result);
    });
  }

enter image description here

| improve this answer | |

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.