Friday, November 12, 2010

Find the userId from a people picke

<script type="text/javascript" src="../../Javascript/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
fields = init_fields();
// Find the userId from a people picker in DispForm
var userIdRaw = $(fields['client']).find('.ms-formbody a').attr('href');
var userId = userIdRaw.substring(userIdRaw.indexOf('=')+1);
// Here is the userId for the person in the people picker
alert(userId);

function init_fields(){
var res = {};
$("td.ms-formbody").each(function(){
if($(this).html().indexOf('FieldInternalName="')<0) return;
var start = $(this).html().indexOf('FieldInternalName="')+19;
var stopp = $(this).html().indexOf('FieldType="')-7;
var nm = $(this).html().substring(start,stopp);
res[nm] = this.parentNode;
});
return res;
}
</script>

No comments:

Post a Comment