0

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.

0

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.

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.