Page 1 of 1
compare current user with person field
Posted: 08 Mar 2020
by May.AlFarsi
Hello,
I am trying to compare the current logged user to a "Assigned To" field that I have on my for
if its a match then I would a confirmation alert box to appear on form submit
if not to save accordingly
I have tried to add the script in different forms but none worked :$
Re: compare current user with person field
Posted: 09 Mar 2020
by Leslie
Go to read my post :
viewtopic.php?f=1&t=3394
I think you can find some usefull information.
Re: compare current user with person field
Posted: 10 Mar 2020
by mnikitina
Hello May.AlFarsi,
I'm sorry for the delayed reply, we were on holiday.
You can use the code below to compare the current logged in user with the user that is selected in the "Assigned To" field on form submit.
Please replace PeoplePicker in the code with the internal name of the "Assigned To" field.
Code: Select all
fd.onsubmit(function() {
//check that PeoplePicker has value
if (fd.field('PeoplePicker ').value().length !=0) {
SP.SOD.executeOrDelayUntilScriptLoaded((function () {
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
ctx.load(web);
var user = web.get_currentUser();
user.retrieve();
ctx.executeQueryAsync(
function () {
//get current user login name
var currentuser = user.get_loginName();
//get login name of the selected user
var assignedTo = fd.field('PeoplePicker ').value()[0].Key;
if(assignedTo==currentuser) {
return confirm('Your text here');
}
else {
return true;
}
});
}), "SP.js");
}
return true;
});