4

Would be very Grateful if you can kindly please help me out

I have a New Item Form with a PeoplePicker field with Allow Multiple Selection setting

The Requirement is the Current User who is filling the form should not fill his email address in the PeoplePicker field

The system should not allow him to save the New Item form

I don't know if this is possible.

Would be very grateful if I can get some assistance please.

i have try the below script which give the current user and The people picker field but its not working on pre save action

<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>

<script type="text/javascript">



var context = null;

var web = null;

var currentUser = null;

ExecuteOrDelayUntilScriptLoaded(GetUserLoginName, "sp.js");

function GetUserLoginName() {

context = new SP.ClientContext.get_current();

web = context.get_web();

this._currentUser = web.get_currentUser();

context.load(this._currentUser);

context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod),

Function.createDelegate(this, this.onFailureMethod));

}

function onSuccessMethod(sender, args) {

var today = new Date();

var peoplepicker=$("#Name_x0020_of_x0020__x0028_Recei_633edcdf-1dc4-4980-ab7e-94a503a6aca5").text(); //change ‘content’ to 

your people picker field ID.

if(peoplepicker!=this._currentUser.get_title())

{

alert(this._currentUser.get_title());

alert(peoplepicker);

 alert('current login user is not equal to people picker column');

Function.createDelegate(this, this.PreSaveAction));
}

}

function onFaiureMethod(sender, args) {

alert('request failed' + args.get_message() + '\n' + args.get_stackTrace());

}
});

 function PreSaveAction()
{

var peoplepicker=$("#Name_x0020_of_x0020__x0028_Recei_633edcdf-1dc4-4980-ab7e-94a503a6aca5").text(); //change ‘content’ to 

your people picker field ID.

if(peoplepicker!=this._currentUser.get_title())

{

alert('current login user is not equal to people picker column');

  return false;
   }
   else
   { 
return true;

 }
   }


</script>

can someone please help me am very new to coding thank you very much

3

As we know that PeoplePicker columns cannot be used in List Validation settings, So I don't think there is any OOTB option to achieve this requirement.

So, what is workaround?

Here I am sharing possible workaround, I haven't tried this requirement, but based on my work on PeoplePicker and customization of default Lists Item Adding form I am sharing the approach.

  • You can overwrite the PreSaveAction() function and keep your required validations within this function. To know the working of PreSaveAction() please refer this.

  • You can always get the Current User ID using _spPageContextInfo.userId

  • In the next step you can get the ID of users selected in the PeoplePicker field by writing some JavaScript stuffs and get the ID of selected users.

  • Now you can compare this IDs and if match found it means that current user is selected in PeoplePicker field, so just return false at the end of the PreSaveAction() function. It will prevent page to add new item.

  • You can either use Content Editor WebPart to put the code or you can directly edit the new form in SharePoint Designer.

Let me know if you need some more assistance.

  • 2
    Hello Sir - Thank you very much -i will try to implement it - the Article you provide me very Good thank you very very much – Arvind Jul 18 '17 at 6:07

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.