Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to update list item's multichoice field? #4831

Closed
Karthickraju2690 opened this issue Oct 29, 2019 · 13 comments
Closed

Question: How to update list item's multichoice field? #4831

Karthickraju2690 opened this issue Oct 29, 2019 · 13 comments
Labels
area:csom/rest/api Category: SharePoint Client Side Object Model SDK / REST API status:answered Answer to a question. type:question Question... if answered, will be tagged as such.

Comments

@Karthickraju2690
Copy link

I can create list item through REST API by using documentation. But, when I try to create list item with Multichoice field,

    {'__metadata': {'type': 'SP.Data.MyListItem'}, 'Title': 'Test Task',
                       'CategoryDescription': 'This is a test Task',                               
                       'Multichoicefield':{
                           '__metadata' : {'type' : 'Collection(Edm.String)' },
                           'results': ['value1', 'value2']
                           }
                       }

On running with above payload, receiving An open collection property 'Multichoicefield' was found. In OData, open collection properties are not supported.", "400 Client Error: Bad Request for url:

Can you provide example of how to create?

@msft-github-bot
Copy link
Collaborator

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

@msft-github-bot msft-github-bot added the Needs: Triage 🔍 Awaiting categorization and initial review. label Oct 29, 2019
@Jerry0527
Copy link

Jerry0527 commented Oct 29, 2019

If your list name is "MyList", the type should be type: "SP.Data.MyListListItem"

Here is a demo to create item with multiple choicefield with Rest API for your reference:

<script type="text/javascript">
    $.ajax  
        ({  
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('MyList')/items",  
        type: "POST",  
        data: JSON.stringify  
        ({  
            __metadata:  
            {  
                type: "SP.Data.MyListListItem"  
            },  
            'Title':  "Test Task",
            'CategoryDescription': "This is a test Task",
            'Multichoicefield': {'results': ['Enter Choice #1', 'Enter Choice #2', 'Enter Choice #3']} 
        }),  
        headers:  
        {  
            "Accept": "application/json;odata=verbose",  
            "Content-Type": "application/json;odata=verbose",  
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),  
            "X-HTTP-Method": "POST"  
        },  
        success: function(data, status, xhr)  
        {  
            console.log(data);
        },  
        error: function(xhr, status, error)  
        {  
            console.log(data.responseJSON.error);  
        }  
    });
    
   </script>

QQ截图20191029174851

@luismanez
Copy link
Contributor

and if memory serves me well, you can see that "type" value if you call:
_/api/lists/getbytitle('MyList')?$select=ListItemEntityTypeFullName

@andrewconnell andrewconnell added area:csom/rest/api Category: SharePoint Client Side Object Model SDK / REST API status:answered Answer to a question. type:question Question... if answered, will be tagged as such. and removed Needs: Triage 🔍 Awaiting categorization and initial review. labels Oct 29, 2019
@Karthickraju2690
Copy link
Author

Karthickraju2690 commented Oct 30, 2019

Thanks Andrew, actually my list name is different and I am using the correct one which I got with the help of _/api/lists/getbytitle('MyList')?$select=ListItemEntityTypeFullName

I am using Python sharePoint online library -Office365-REST-Python-Client to create new list item. I am able to successfully create new list.

Only when I try to create new list with Multi-choice field, I receive an error
An open collection property 'Multichoicefield' was found. In OData, open collection properties are not supported.", "400 Client Error: Bad Request for url:

Seems like OData stopped supporting this.

Note: Have already tried like 'Multichoicefield': {'results': ['value1', 'value2']}, but couldn't be successful as it throws A value without a type name was found and no expected type is available. When the model is specified, each value in the payload must have a type which can be either specified in the payload, explicitly by the caller or implicitly inferred from the parent value.. so, I had to use 'Multichoicefield':{ '__metadata' : {'type' : 'Collection(Edm.String)' }, 'results': ['value1', 'value2'] }

I've already raised the issue on library's Github page here

@Jerry0527
Copy link

Jerry0527 commented Oct 30, 2019

You can add a new item with multi choice field in the UI firstly and then check the Json response with Rest:

_api/web/lists/getbyTitle('MyList')/items

Make sure the field name is valid and the value should be mateched in the field settings:

QQ截图20191030160817

@Karthickraju2690
Copy link
Author

I can add new item with multi choice field through UI and below is the detail:

image

@Jerry0527
Copy link

'Multichoicefield': {'results': ['Enter Choice #1', 'Enter Choice #2', 'Enter Choice #3']} works in my side, change fieldname and choice option with yours for a test.

@Karthickraju2690
Copy link
Author

I've tried Jerry.

Error is An open collection property 'Multichoicefield' was found. In OData, open collection properties are not supported.", "400 Client Error: Bad Request for url:

It seems like problem is with OData. When do we get this error? On what scenario will this be thrown?

@Jerry0527
Copy link

You can test with JavaScript firstly, as I can't reproduce the error you are meeting in my side. Then migrate to Python.

@Karthickraju2690
Copy link
Author

Karthickraju2690 commented Oct 30, 2019

I am not much familiar with that.... I can see your code above, but doesn't have authentication part. Can you share complete example to test or if you can share a link that would be helpful

@Jerry0527
Copy link

My code snippet above is a complete example....
If you want to learn about call Rest API with Jquey ajax, please refer here:

CRUD Operations On A SharePoint List Using REST API

@msft-github-bot
Copy link
Collaborator

Closing issue as "answered". If you encounter similar issue(s), please open up a NEW issue. Thank you.

@SharePoint SharePoint locked as resolved and limited conversation to collaborators Nov 2, 2019
@msft-github-bot
Copy link
Collaborator

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area:csom/rest/api Category: SharePoint Client Side Object Model SDK / REST API status:answered Answer to a question. type:question Question... if answered, will be tagged as such.
Projects
None yet
Development

No branches or pull requests

5 participants