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?

1 Answer 1

1

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.

3
  • Thank you, it works perfectly! Commented Jun 25, 2021 at 12:23
  • Glad I could help Commented Jun 25, 2021 at 14:39
  • Great blog post!
    – Ama
    Commented Nov 9, 2023 at 22:02

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.