compare current user with person field
-
- Posts: 9
- Joined: Wed Jun 29, 2016
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 :$
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 :$
Go to read my post : viewtopic.php?f=1&t=3394
I think you can find some usefull information.
I think you can find some usefull information.
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.
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;
});
-
- Information
-
Who is online
Users browsing this forum: No registered users and 25 guests