Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

JS and REST - Posting to a Person/Group field in a list

$
0
0

Hi All,

I'm using JavaScript JSOM to write back to a list in the HostWeb in a SharePoint-Hosted Application.

Text fields update correctly but I'm getting a "Bad Request" error if I try to write back to a field which has been defined as a "Person/Group" field.

    executor.executeAsync(
        {
            url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('SiteRequests')/items?@target='" + target + "'",
            method: "POST",
            body: JSON.stringify({
                '__metadata': { 'type': 'SP.Data.SiteRequestsListItem' },
                Title: siteTitle,
                Template: "Blah",
                Owner: getSiteOwner(),
                Secondary: getSecondaryOwner(),
                XX: "Butlers"
            }),
            headers: {"Accept": "application/json; odata=verbose","content-type": "application/json;odata=verbose",
                },
            success: successHandlerForNewListItems,
            error: errorHandler
        }
        );

In this example - XX is the field in Question....  I've tried the following formats :-

Username (butlers)

domain\username (mydomain\butlers)

claim token (i:0#.w|mydomain\butlers)

user id as an integer : 1

All fail with the same error.

Is anybody able to provide some boilerplate syntaxt to POST to a Person Field please?

If it needs to be an ID - any suggestion as to how to obtain that from etiher the domain\username or claim token name would be much appreciated as the only properties I'm (seemingly) able to return inside my Javascript Client People Picker are :-

Key: i:0#.w|mydomain\butlers

Description: mydomain\butlers
DisplayText: Steve Butler
EntityType: User
ProviderDisplayName: Active Directory
ProviderName: AD
IsResolved: true
EntityData: [object Object]
MultipleMatches:
AutoFillKey: i:0#.w|mydomain\butlers
AutoFillDisplayText: Steve Butler
AutoFillSubDisplayText:
AutoFillTitleText: Active Directory mydomain\butlers
DomainText: app-af2d81df7dcb8a.myfullyqualifiedisolatedappdomain
Resolved: true
LocalSearchTerm: butler

Thanks

Steve


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>