0

I'm trying to create a new list item in a SharePoint document library, but I have an error when I set a value in a multi-choice field.

This is the body of the post request:

{
    "listItemCreateInfo": {
        "FolderPath": {
            "DecodedUrl": "......."
        },
        "UnderlyingObjectType": 1
    },
    "formValues": [
        {
            "FieldName": "MultiChoice",
            "FieldValue": [
                "Scelta n. 1",
                "Scelta n. 3"
            ],
        },       
        {
            "FieldName": "FileLeafRef",
            "FieldValue": "2021-000001010"
        },        
        {
            "FieldName": "ContentTypeId",
            "FieldValue": "0x0120D5200062FEFD4873814585B3EFD57010F1F8AE"
        }
    ],
    "bNewDocumentUpdate": false
}

And this is the error:

An unexpected 'StartObject' node was found when reading from the JSON reader. A 'PrimitiveValue' node was expected

I tried the following solutions:

    "FieldValue": [
        "Scelta n. 1",
        "Scelta n. 3"
    ],

    "FieldValue": "{'results':[
        'Scelta n. 1',
        'Scelta n. 3'
    ]}",

but they all failed.

How should I create the JSON?

0

Instead of setting FieldValue to an array, set it to a string with the choice values separated by ";#". In the example you give above the JSON would become:

{
    "listItemCreateInfo": {
        "FolderPath": {
            "DecodedUrl": "......."
        },
        "UnderlyingObjectType": 1
    },
    "formValues": [
        {
            "FieldName": "MultiChoice",
            "FieldValue": "Scelta n. 1;#Scelta n. 3"
        },       
        {
            "FieldName": "FileLeafRef",
            "FieldValue": "2021-000001010"
        },        
        {
            "FieldName": "ContentTypeId",
            "FieldValue": "0x0120D5200062FEFD4873814585B3EFD57010F1F8AE"
        }
    ],
    "bNewDocumentUpdate": false
}

This blog post shows the format that should be use for field values of different types: Update the value of the field using the validateUpdateListItem method.

2
  • Thank you, it works perfectly! Jun 25 at 12:23
  • Glad I could help Jun 25 at 14:39

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.