1

On my SharePoint online (version 16.0.0.5312), when I retrieve items through REST api: /some-site/_api/web/lists/getbyTitle('ListName')/items(3), the API returns a new property for User-type fields.

I have a user-type field called "AssignedTo" and the SharePoint call returns:

{
    Title: 'Title value',
    AssignedToId: 21,
    AssignedToStringId: "21",
    . . .
} 

The next code creates a new item on this list and "Assign it To" user 21:

executor.executeAsync({
    url: "/some-site/_api/web/lists/getByTitle('ListName')/items",
    method: "POST",
    body: "{ '__metadata': { 'type': 'SP.Data.ListNameListItem' },
        'Title': 'Title value',
        'AssignedToId': 21,
        . . .  },
     headers: { 
        "accept": "application/json;odata=verbose",
        "content-type": "application/json;odata=verbose"
    },
    success: successHandler,
    error: errorHandler
});

Note: We must use field-name + Id in order to refer User and Lookup fields.

If I want to modify this field value on a item, in SharePoint 2013, I use the next code:

executor.executeAsync({
    url: "/some-site/_api/web/lists/getByTitle('ListName')/items(2)",
    method: "POST",
    body: "{ '__metadata': { 'type': 'SP.Data.ListNameListItem' },
        'Title': 'New title value',
        'AssignedToId': 99,
        . . .  },
     headers: { 
        "IF-MATCH": "*",
        "X-HTTP-Method": "MERGE",
        "content-type": "application/json;odata=verbose"
    },
    success: successHandler,
    error: errorHandler
});

The problem is that now, on SharePoint online, this code throws a server error!!.

As I mentioned before, a new property appears for User-type fields. The new property is field-name + StringId, and you must use it to update correctly the item value.

For update operations, use the next code:

executor.executeAsync({
    url: "/some-site/_api/web/lists/getByTitle('ListName')/items(3)",
    method: "POST",
    body: "{ '__metadata': { 'type': 'SP.Data.ListNameListItem' },
        'Title': 'New title value',
        'AssignedToStringId': '99',
        . . .  },
     headers: { 
        "IF-MATCH": "*",
        "X-HTTP-Method": "MERGE",
        "content-type": "application/json;odata=verbose"
    },
    success: successHandler,
    error: errorHandler
});

Don't forget to assign the value as a string.

This only apply to update operations. For new items, I must keep using "AssignedToId" property.

Someone knows this new behavior about "...StringId" properties? It's just a bug of the new 2016 version or a definitive guideline.

Thanks, Pau

1 Answer 1

1

The user-type field called AssignedTo is a lookup field which uses the ID of the user (Username) you have entered.

So you will definitely get the ID or you can only set the ID inplace of username.

That is not a bug of new 2016 version

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.