SharePoint Asked by Ben Short on December 2, 2021
I’m currently writing an initialisation script for a SharePoint-hosted application which checks if a list (used for launcher items) exists. If it doesn’t, then it runs through a series of processes to create the list, add fields and then update the view.
Here’s a snippet of code which loops through the payload objects and creates a new field and adds said field to the view for each object. This script utilises AngularJS and ShareCoffee.
var payload = [{
'Title': 'Icon URL',
'FieldTypeKind': 11,
'Required': true
},
{
'Title': 'Destination URL',
'FieldTypeKind': 11,
'Required': true
}];
angular.forEach(payload, function (value, key) {
$http(ShareCoffee.REST.build.create.for.angularJS({ url: 'web/lists/getByTitle('Launcher%20Items')/Fields', payload: payload[key], hostWebUrl: hostweburl }))
.success(function (data) {
console.log('Created field with the title ' + payload[key].Title);
// field created, add to view
$http(ShareCoffee.REST.build.create.for.angularJS({ url: 'web/lists/getByTitle('Launcher%20Items')/views/getByTitle('All%20Items')/viewFields/addViewField('' + payload[key].Title + '')', hostWebUrl: hostweburl }))
.success(function (data) {
console.log('Added element to view');
})
.error(function (data, status) {
console.log(status);
console.log(data);
})
})
.error(function (data, status) {
console.log(status);
console.log(data);
});
}
This code should work fine, but when it runs I get an Error 400 response from SharePoint with the error code
1, Microsoft.SharePoint.Client.InvalidClientQueryException
As well as a message saying
value: “Cannot handle the data at position 0.”
Is there any reason why this would happen or what this means? Google doesn’t seem to bring much back.
The issues appears to be that rather than 'creating' a new record within the viewField, you instead 'update' the existing record.
Replacing the REST.build.create class with REST.build.update seems to resolve the issue.
Answered by Ben Short on December 2, 2021
1 Asked on November 13, 2021 by kathyb
1 Asked on November 11, 2021 by ciprian
1 Asked on November 11, 2021 by ricardo-rodrigues
1 Asked on November 11, 2021 by gaurav-goyal
sharepoint framework spfx spfx extensions spfx tooling spfx webparts
1 Asked on November 11, 2021 by matt-minton
0 Asked on November 11, 2021 by jeff-o
3 Asked on November 8, 2021 by marlou
1 Asked on November 8, 2021 by syagla
1 Asked on November 8, 2021 by dk20202
approval approval process custom list office 365 sharepoint online
1 Asked on November 8, 2021 by powerbi87
3 Asked on November 5, 2021 by adam13hylo
2 Asked on November 5, 2021 by lakshmi
designer workflow sharepoint designer sharepoint foundation sharepoint list sharepoint online
1 Asked on November 5, 2021
3 Asked on November 5, 2021
custom list document document library list view sharepoint server
1 Asked on November 5, 2021 by sooraj-nair
sharepoint calendar sharepoint enterprise sharepoint online task list user tracking
1 Asked on November 5, 2021 by seaandtea
1 Asked on October 26, 2021 by noah-m
2 Asked on October 26, 2021 by anand-pipaliya
document library sharepoint designer sharepoint online site collection web part
1 Asked on October 26, 2021 by spdev
Get help from others!
Recent Answers
Recent Questions
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP