1

I have implemented post method for inserting userid into list.

So how to check whether inserted User Id exists in SharePoint list or not,in angularJS

2 Answers 2

1

You can get the currently logged in user in sharepoint by following code:

var userId = _spPageContextInfo.userId;

After that before showing popup, make a REST call on the list to check the current user is already exist in list or not. (Assuming your column in list is of people and group type and name is "LoggedUsers").

$.ajax({
          url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('ListName')/items$select=Title,LoggedUsers/Id&$expand=LoggedUsers&$filter=LoggedUsers/Id eq " + userId,
method: "GET",
headers: {
    "Accept": "application/json; odata=verbose" 
},
    success: function (data) {
        console.log(data);
    },
    error: function (data) {
        console.log(data);
    }
});

If you got any results through this call, then hide the popup or if didn't got any results, then show popup to add current user in list.

Ignore the typos and please upvoted if this answer helped you in any way.

0

Use the /_api/web/ensureUser service. Here are the ajax instructions. The specific post you make through angular depends on the version you are using.

Broadly, though, something like this for angularJS :

//the call to the service, using post headers w/ X-RequestDigest
postDataAsync(url, JSON.stringify({ 'logonName': user }), headers).then(function (response) {

});

//the service
postdataasync(url, data, spHeaders){
   $http.post(url, data, { headers: spHeaders }).then(function (response) {

   }, function(error){}
});

});

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.