0

I need to update the some columns(EmpId,DocumentDate,PRType,Commnunity) in my document library.Out of which PRType & Community is managed metadata column. All works file and updated when I update only EmpId & DocumentDate, but as soon as I added "PRType":{'label':'TermName','TermGuid':'GUID of Term','WssId':-1} & Community in my metadata to update it gives 400 error. So metadata column not updated, where I went wrong in updating the metadata column.


   var fileUrl=`https://xxxxx.sharepoint.com/sites/TestSite/_api/Web/Lists/getByTitle('Drop%20Off%20Library')/Items(id)`;
 
   const body = {
    '__metadata': { 'type': 'SP.Data.DropOffLibraryItem' }, "EmpId": "021345","DocumentDate":"Date"
    ,"PRType":{'label':'TermName','TermGuid':'GUID of Term','WssId':-1}
    ,"Community":{'label':'TermName','TermGuid':'GUID of Term','WssId':-1}
};
   
   let spOpts1 : ISPHttpClientOptions  = {
    headers: {
        'IF-MATCH': '*',
        'Content-type': 'application/json;odata=verbose',
        "accept": "application/json;odata=verbose",
        "odata-version":"3.0",
        'X-HTTP-Method': 'MERGE'
    },
    body: JSON.stringify(body)       
  };
   
   this.props.context.spHttpClient.post(fileUrl,SPHttpClient.configurations.v1,spOpts1).then((response: SPHttpClientResponse) => {
    alert(response.status + ':' + response.ok);        
        }) 
    }```
1
  • Did you get any solution? I am facing the same issue – Acc Aditya Dec 24 '20 at 11:19
0
let requestUrl = this.context.pageContext.web.absoluteUrl.concat(“/_api/web/lists/getbytitle(‘YourListTitle’)/items(ListItemId)”);   

let dataToPost = JSON.stringify({   

    ‘__metadata’: {   

        ‘type’: ‘SP.Data.YourListTitleListItem’   

    },   

    “TermFieldSingle”:{ 

        “Label”:”Test Value 1″, 

        “TermGuid”:”GUID of the Term”, 

        “WssId”:-1 //which make sure to create an entry in TaxonomyHiddenList if not added. 

        }  

});   

let spOpts = {   

    headers: { 

        ‘Accept’: ‘application/json;odata=nometadata’, 

        ‘Content-type’: ‘application/json;odata=verbose’, 

        ‘odata-version’: ”, 

        ‘IF-MATCH’: ‘*’, 

        ‘X-HTTP-Method’: ‘MERGE’ 

    }, 

    body: dataToPost   

};   

this.context.spHttpClient.post(requestUrl, SPHttpClient.configurations.v1, spOpts).then((response: SPHttpClientResponse) => {   

    if (response.ok) {   

        response.json().then((responseJSON) => {   

            console.log(responseJSON);   

        });   

    }   

});   

Try this!

3
  • Already try this one, gives same error – Ashutosh Agarwal Jun 20 '20 at 16:14
  • Is your column on the doc library is Single Valued or Multi Valued? – spgk Jun 20 '20 at 17:37
  • I have a 2 singled valued managed metadata column, need to update both – Ashutosh Agarwal Jun 21 '20 at 2:00

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.