5

I have a function in presave that takes the user name in the people picker available on the form and do some business logic. After completion of script the actual save function is called.

The issue is that if the value entered in people picker is not resolved (even if the value is valid name) then the value is not received correctly in the presave function.

I have tried to call the click of people picker resolution but since its asynchronous function i cannot get the entire value ie. domain/alias before my further code starts executing.

Any idea on how to achieve this.

1
  • 1
    have u tried like this.. var valueOfPeloplePicker = $("[id$='upLevelDiv']").text(); Dec 28, 2012 at 9:38

3 Answers 3

4

In order to check (on the client side) if the value entered in people picker is resolved the following function could be used

//Determines If People Picker value is resolved (using jQuery)
function IsPeoplePickerValueResolved() { 
   var eEntityData = $("div[id='divEntityData']");
   if(eEntityData.length > 0 ) {
       var isResolved = eEntityData.attr("isresolved");
       return (isResolved == "True"); 
   }    
   return false;
}

Gist link

Usage

function PreSaveAction() { 
   var isResolvedUser = IsPeoplePickerValueResolved();
   //...   
   return true;
}

For example,

enter image description here

returns false


enter image description here

returns true

0

You could try using the SPServices library to get a handle on the field and initiate a name resolution through JavaScript. In specific, take a look at the SPFindPeoplePicker function:

$().SPServices.SPFindPeoplePicker

http://spservices.codeplex.com/wikipage?title=%24%28%29.SPServices.SPFindPeoplePicker

Take a look at the checkNames section:

checkNames

This is a reference to the checkNames img tag in the People Picker. It’s used by the function to initiate resolution of a Person or Group value by firing the click event on it. Once you have this reference, you can do the same.

You could probably also figure out how to do this on your own without the use of SPServices. Just get a handle on the image and initiate a click().

3
  • I just re-read your question and realized you tried essentially doing this. Have you tried initiating the resolution onblur, when the person leaves the field?
    – user8344
    Dec 28, 2012 at 16:18
  • but if the mouse control is on the people picker and then directly "Save" is clicked then onblur will not fire. So it won't be of any help to me. Dec 31, 2012 at 5:05
  • click() event of image is also asynchronous so i cannot control my code after that Dec 31, 2012 at 5:07
0

$().SPServices.SPFindPeoplePicker does not work. The method is not supported on a person/group field.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.