1

I have a SharePoint Hosted Add-In where I've come so far as to Post a user into a "Multiple Users and Groups" field by the users ID and it works great.

The problem I have is that when I try to remove one user from this field I'm not able to find the right solution.

I have tried using REST with no luck:

Ajax.Delete("../_api/web/lists/getbytitle('List')/Items(3)/$links/Multiple_Users_Field(9)").done(done).fail(DoError.Ajax)
Ajax.Delete("../_vti_bin/listdata.svc/List(3)/$links/Multiple_Users_Field(9)").done(done).fail(DoError.Ajax)
Ajax.Delete("../_api/web/lists/List(3)/$links/Multiple_Users_Field(9)").done(done).fail(DoError.Ajax)

Errors thrown are as follows:

"Cannot find resource for the request $links."
"Resource not found for the segment 'Multiple_Users_Field'."
"Cannot find resource for the request List."

Anyone have any suggestions to this problem?

0

Figured it out myself!

It was a simple Patch that was needed, this works but it feels like it's unnecessary to loop through the entire collection of people every time one user wants to interact with the field...

Ajax.Get("../_api/web/lists/getbytitle('List')/items(" + thisList.ID + ")?$select=Multiple_Users_Field/Id&$expand=Multiple_Users_Field").then(function (data) {

    var idArray = [], users = data.d.Multiple_Users_Field.results;
    for (var i = 0; i < users.length; i++) { idArray.push(users[i].Id); }

    if ($.inArray(currentUserID, idArray) !== -1) idArray.splice(idArray.indexOf(currentUserID), 1);
    else idArray.push(currentUserID);

    Ajax.Update(thisList.URI, {
        __metadata: { 'type': 'SP.Data.ListListItem' },
        "Multiple_Users_FieldId": { 'results': idArray }
    }).fail(DoError.Ajax);

}, DoError.Ajax);
0

you refer below script for removing one user

function Delete()
{ 
jQuery.ajax({url: _spPageContextInfo.webAbsoluteUrl+"/_vti_bin/listdata.svc/List(3)/$links/Multiple_Users_Field(9)",
type: "POST",
headers: {
"ACCEPT": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": jQuery("#__REQUESTDIGEST").val(),   
"X-HTTP-Method": "DELETE"
},
success: function (data) {                     
alert("Deleted Successfuly.");
},
error: function (error) {
alert('n')
}
});
}
  • Doesn't work, still getting this error: "Resource not found for the segment 'Multiple_Users_Field'" – Fredrik Johan Lund Aug 10 '16 at 6:24
  • Can you just check by trying with field name as "Multiple_Users_FieldId" in place of "Multiple_Users_Field" – Sunil Sahu Aug 10 '16 at 6:40
  • Still the same error :/ "Resource not found for the segment 'Multiple_Users_FieldId'" – Fredrik Johan Lund Aug 10 '16 at 8:39
  • I tested the above code block work fine for me, can you please check with the internal name for 'Multiple_Users_Field' (without using Id) and try again. hope it works. – Sunil Sahu Aug 10 '16 at 8:53
  • The internal name is correct, could it be because this is a field added in visual studio for a custom list in a SharePoint Hosted App? – Fredrik Johan Lund Aug 10 '16 at 11:32

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.