compare current user with person field

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
May.AlFarsi
Posts: 9
Joined: Wed Jun 29, 2016

08 Mar 2020

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 :$

Leslie
Posts: 32
Joined: Thu Dec 05, 2019

09 Mar 2020

Go to read my post : viewtopic.php?f=1&t=3394
I think you can find some usefull information. :)

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

10 Mar 2020

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;
});

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 25 guests