TransWikia.com

REST addViewField "Cannot handle the data at position 0."

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.

One Answer

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

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP