This SharePoint rest api tutorial explains, how to update people picker group field using Rest API and jQuery in SharePoint 2013/2016. We will fix issue incorrect format field name not supported which comes while updating or setting the value for a people group field in SharePoint list.
When I was using the below Rest API code to set the loan applicant name (person and group field) I was getting the error as “incorrect format field name not supported” in SharePoint.
I was writing the below Rest API code.
function updateLoanApplicantDetails(itemTitle, listName, siteUrl, title,lnFstName ,applicantID, success, failure) {
var itemType = GetItemTypeForListName(listName);
var item = {
"__metadata": { "type": itemType },
"Title": title,
"FirstName":lnFstName,
"applicantNameId": applicantID
};
getListItemWithTitle(itemTitle, listName, siteUrl, function (data) {
$.ajax({
url: data.__metadata.uri,
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(item),
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"X-HTTP-Method": "MERGE",
"If-Match": "*"
//data.__metadata.etag
},
success: function (data) {
success(data);
},
error: function (data) {
failure(data);
}
});
}, function (data) {
failure(data);
});
}
Issue:
I tried setting the people group value by sending email-id or user-id with domain but there was no luck with neither of them.
Update People Picker Group field using Rest API and jQuery in SharePoint
If we want to update the people group field in SharePoint we have to set the user profile ID of the required/selected user as part of the REST call.
Provide email-ID or domain of the required user as part of the form
Search whether that user is existed as part of User Profile or not with the below call
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/siteusers?$filter=substringof('"+$('#txtApplnEmlID').val()+"',Email) eq true";
In the above example I am searching the user with email-ID
If the user is as part of the User-Profile get the ID of the user
Set that user profile ID to people picker control
Follow the below important note
Note: To set more than one value in people group follow the below syntax:
applicantNameId: {'results': [11,12]}
in this example 11, 12 are user profile-ID's
The complete solution is as follows:
// Applicant Details —————– Start ——————
$("#btnApplName").click(function(){
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/siteusers?$filter=substringof('"+$('#txtApplnEmlID').val()+"',Email) eq true";
$.ajax({
url: requestUri,
type: "GET",
headers: {
"accept": "application/json; odata=verbose"
},
success: onSuccess,
error: onError
});
function onSuccess(data) {
var objItems = data.d.results;
var applnEmail = "";
for (var i = 0; i < objItems.length; i++) {
applnEmail = objItems[i].Id; // Getting the User Profile-ID
}
if(objItems.length>0)
{
updateLoanApplicantDetails($('#chEditLnNumers').find(":selected").val(),"loanInformation",_spPageContextInfo.webAbsoluteUrl, $('#txtEdLnID').val(),$('#txtEdFstNm').val(),$('#txtEdLstNm').val(),$('#txtEdLnAmnt').val(), applnEmail,function(){
alert("User got Email-ID updated Successfully");
},function(){
alert("Error in adding user Details");
});
}
else
{
alert("Applicant Email-ID is not valid");
}
}
function onError(error) {
alert('Error');
}
});
function updateLoanApplicantDetails(itemTitle, listName, siteUrl, title,lnFstName, lnLstName, lnAmnt, applicantID, success, failure) {
var itemType = GetItemTypeForListName(listName);
var item = {
"__metadata": { "type": itemType },
"Title": title,
"FirstName":lnFstName,
"applicantNameId": applicantID
};
getListItemWithTitle(itemTitle, listName, siteUrl, function (data) {
$.ajax({
url: data.__metadata.uri,
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(item),
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"X-HTTP-Method": "MERGE",
"If-Match": "*"
//data.__metadata.etag
},
success: function (data) {
success(data);
},
error: function (data) {
failure(data);
}
});
}, function (data) {
failure(data);
});
}
// Applicant Details —————– End ——————
You may like following SharePoint Rest API tutorials:
- Create custom SharePoint Survey poll using REST API and AngularJS
- Retrieve and Display TASK status using REST API in SharePoint
- Create a Custom Calendar in SharePoint using Rest API and jQuery
- Display SharePoint list data in jQuery data table using Rest API
- Create Highcharts in SharePoint using Rest API
- SharePoint Rest API Crud Operations
- Add Google ReCaptcha in SharePoint Online or SharePoint 2013/2016/2019 (Step by Step tutorial)
- Google Pie Chart in SharePoint Online (Step by Step tutorial)
- Get Manager Name based on employee Name using Client People Picker in SharePoint Online
- Different operations on SharePoint 2013 people picker
- How to use client side People Picker control in SharePoint online Office 365?
- How to get documents from document library in SharePoint using Rest API
Hope this helps you to update the People Picker Group field using Rest API and jQuery in SharePoint 2013.
I am Krishna.Vandanapu a SharePoint architect working in IT from last 13+ years, I worked in SharePoint 2007, 2010, 2013, 2016 and Office 365. I have extensive hands on experience in customizing SharePoint sites from end to end. Expertise in SharePoint migration tools like Sharegate, Doc Ave and Metalogix. Migrated SharePoint sites from SharePoint 2007 to 2010 and 2010 to 2013 several times seamlessly. Implementing CSOM with Microsoft best practices. Spent quality time in configuring SharePoint application services like User Profile, Search, Managed Meta data services etc. Now exploring SharePoint Framework and SharePoint 2019
[…] Update People Picker Group field using Rest API and jQuery in SharePoint 2013/2016 […]