zondag 11 januari 2015

Check or Get People Picker value.


New function to check if a people picker field is empty or to get the value of a people picker field.
Functions that may be usefull to use in presave actions when editing or creating new list items. 

The function IsPeoplePickerEmpty must be called with a parameter that contains the title of your field. Or with the value of the text that stands on the left side of your people picker field. 

The function  GetPeoplePickerValue must be called with a parameter that contains the title of your field. Or with the value of the text that stands on the left side of your people picker field. It returns a string containing the key of your people picker field. This is the domain and userid of the inserted value. 

Remark. The GetPeoploePickerValue only works with a single user People Picker field. 

 
function IsPeoplePickerEmpty( titel )
{
  if (( $('nobr:contains("'+ titel +'")').closest("td").next("td").find('input')[1].value  == " ") || ( $('nobr:contains("'+ titel +'")').closest("td").next("td").find('input')[1].value  == "") )
         return true;
  else
         return false;
}
function GetPeoplePickerValue(titel)
{
    var result = "";
        if (!IsPeoplePickerEmpty(titel))
        {
                result = $('nobr:contains("'+ titel +'")').closest("td").next("td").find('input')[1].value;
                result = result.substring(result.indexOf("key=") + 5 );
                result = result.substring(0,result.indexOf("'"));
        }
    return result;
}

Geen opmerkingen:

Een reactie posten