Retrieving the Person Field User ID

Dec 28, 2009 at 7:46 PM

I am using a modified version of the jPoint.userprofile.js to pull user info from "/_layouts/userdisp.aspx".  So when I add a person into a person field I need it to fire and pull info based on person in this field, NOT the current user.  I am populating information on the rest of the form based on this.  This works wonderfully if I am looking for current users in.  How can I use jPoint to derive the ID from this person field?

Coordinator
Dec 29, 2009 at 4:59 PM
Edited Dec 30, 2009 at 4:50 AM

Very good question!

I have updated jpoint.userprofile.js to accommodate your user case.  This is how to use this feature:

 

<script src="http://sharejpoint.googlecode.com/files/jPointLoader.js"></script>
<script src="http://www.sharejpoint.com/src/jpoint/plugins/jPoint.userprofile.js"></script>

<div id="outdiv" />

<script>

$(document).ready(function(){

jP.Form.readForm(); //Reading the form

var UserName = jP.Form["Person"].val(); //This line needs to be changed to reflect person field on your form 

jP.WebServices.GetUserInfo({userLoginName:UserName});

  var user = jP.getUserProfile(jP.WebServices.Result.data.User0.NodeAttr.ID); //Calling getUserProfile with userID from the webservice call

//Displaying data

  if(!user) {alert("User not found. Please sign in!"); return;}

  var out = "";

  out += "<b>The current login user account is <font color=red>"+user.Account+"</font></b>"

  out += "<table>";

  out += "<tr><th>Field Name</th><th>Field Value</th><th>jPoint Code</th></tr>";

  $.each(user.Fields, function(i, field){

    out += "<tr><td>"+field+"</td><td>"+user[field]+"</td><td>jP.UserProfile."+field+"</td></tr>";

  });

  out += "</table>";

  $("#outdiv").html(out);

});

</script>

 

<script type="text/javascript" src="/eon/dev/samir/Shared Documents/jPoint-0.8/jPoin*tLoader.j
<script src="/eon/dev/samir/Shared Documents/jPoint-0.8/plugins/jPoint.userprofile.js"></script>
<div id="outdiv" />
<script>
$(document).ready(function(){
jP.Form.readForm();
jP.Form.AssignedTo.val('eonuser:will.ctr.lawrence');
jP.WebServices.GetUserInfo({userLoginName:jP.Form.AssignedTo.val()});
debugger;
  var user = jP.getUserProfile(jP.WebServices.Result.data.User0.NodeAttr.ID);
  if(!user) {alert("User not found. Please sign in!"); return;}
  var out = "";
  out += "<b>The current login user account is <font color=red>"+user.Account+"</font></b>"
  out += "<table>";
  out += "<tr><th>Field Name</th><th>Field Value</th><th>jPoint Code</th></tr>";
  $.each(user.Fields, function(i, field){
    out += "<tr><td>"+field+"</td><td>"+user[field]+"</td><td>jP.UserProfile."+field+"</td></tr>";
  });
  out += "</table>";
  $("#outdiv").html(out);
});
</script>
Coordinator
Dec 30, 2009 at 1:15 AM
Edited Dec 30, 2009 at 1:16 AM
Give us a little more time with this script.  It looks like Samir has posted a reference to a non-public URL.  Also, we will show the entire code written with the onchange event to the Person field and everything
- Will
samirsijercic wrote:

Very good question!

I have updated jpoint.userprofile.js to accommodate your user case.  This is how to use this feature:

 

<script type="text/javascript" src="/eon/dev/samir/Shared Documents/jPoint-0.8/jPointLoader.js" ></script>

<script src="/eon/dev/samir/Shared Documents/jPoint-0.8/plugins/jPoint.userprofile.js"></script>

<div id="outdiv" />

<script>

$(document).ready(function(){

jP.Form.readForm(); //Reading the form

var UserName = jP.Form["Person"].val(); //This line needs to be changed to reflect person field on your form 

jP.WebServices.GetUserInfo({userLoginName:UserName});

  var user = jP.getUserProfile(jP.WebServices.Result.data.User0.NodeAttr.ID); //Calling getUserProfile with userID from the webservice call

//Displaying data

  if(!user) {alert("User not found. Please sign in!"); return;}

  var out = "";

  out += "<b>The current login user account is <font color=red>"+user.Account+"</font></b>"

  out += "<table>";

  out += "<tr><th>Field Name</th><th>Field Value</th><th>jPoint Code</th></tr>";

  $.each(user.Fields, function(i, field){

    out += "<tr><td>"+field+"</td><td>"+user[field]+"</td><td>jP.UserProfile."+field+"</td></tr>";

  });

  out += "</table>";

  $("#outdiv").html(out);

});

</script>

 

<script type="text/javascript" src="/eon/dev/samir/Shared Documents/jPoint-0.8/jPointLoader.js" ></script>
<script src="/eon/dev/samir/Shared Documents/jPoint-0.8/plugins/jPoint.userprofile.js"></script>
<div id="outdiv" />
<script>
$(document).ready(function(){
jP.Form.readForm();
jP.Form.AssignedTo.val('eonuser:will.ctr.lawrence');
jP.WebServices.GetUserInfo({userLoginName:jP.Form.AssignedTo.val()});
debugger;
  var user = jP.getUserProfile(jP.WebServices.Result.data.User0.NodeAttr.ID);
  if(!user) {alert("User not found. Please sign in!"); return;}
  var out = "";
  out += "<b>The current login user account is <font color=red>"+user.Account+"</font></b>"
  out += "<table>";
  out += "<tr><th>Field Name</th><th>Field Value</th><th>jPoint Code</th></tr>";
  $.each(user.Fields, function(i, field){
    out += "<tr><td>"+field+"</td><td>"+user[field]+"</td><td>jP.UserProfile."+field+"</td></tr>";
  });
  out += "</table>";
  $("#outdiv").html(out);
});
</script>

 

Coordinator
Jan 6, 2010 at 5:30 PM

 

<! --This example uses people picker to show user data upon a people picker change -->
<!-- It displays data in div, but user can format to display this data in other more useful methods -->
<script src="//sharejpoint.googlecode.com/files/jPointLoader.js"></script>
<script src="//www.sharejpoint.com/src/jpoint/plugins/jPoint.userprofile.js"></script>
<div id="outdiv" />
<script>
$(document).ready(function(){
jP.Form.readForm(); //Reading the form
//My person field is called "Assigned To". Here change all "AssignedTo" to field name from your form 
$(jP.Form["AssignedTo"].ItemRow).find('TEXTAREA, .ms-inputuserfield').focus(function(){getUserInfo(jP.Form["AssignedTo"].val());}).blur(function(){getUserInfo(jP.Form["AssignedTo"].val());}).change(function(){getUserInfo(jP.Form["AssignedTo"].val());});
});
function getUserInfo(UserName)
{
jP.WebServices.GetUserInfo({userLoginName:UserName});
if(jP.WebServices.Result.data.User0 != null)
{
  var user = jP.getUserProfile(jP.WebServices.Result.data.User0.NodeAttr.ID); //Calling getUserProfile with userID from the webservice call
//Displaying data
  if(!user) {alert("User not found. Please sign in!"); return;}
  var out = "";
  out += "<b>The current login user account is <font color=red>"+user.Account+"</font></b>"
  out += "<table>";
  out += "<tr><th>Field Name</th><th>Field Value</th><th>jPoint Code</th></tr>";
  $.each(user.Fields, function(i, field){
    out += "<tr><td>"+field+"</td><td>"+user[field]+"</td><td>jP.UserProfile."+field+"</td></tr>";
  });
  out += "</table>";
  $("#outdiv").html(out);
}
else
{
  $("#outdiv").html('');
}
}
</script>

<! --This example uses people picker to show user data upon a people picker change -->

<!-- It displays data in div, but user can format to display this data in other more useful methods -->

<!-- If page is loading slowly for you then copy js files locally and reference local files  -->

<script src="//sharejpoint.googlecode.com/files/jPointLoader.js"></script>

<script src="//www.sharejpoint.com/src/jpoint/plugins/jPoint.userprofile.js"></script>

<div id="outdiv" />

<script>

$(document).ready(function(){

jP.Form.readForm(); //Reading the form

//My person field is called "Assigned To". Here change all "AssignedTo" to field name from your form 

$(jP.Form["AssignedTo"].ItemRow).find('TEXTAREA, .ms-inputuserfield').focus(function(){getUserInfo(jP.Form["AssignedTo"].val());}).blur(function(){getUserInfo(jP.Form["AssignedTo"].val());}).change(function(){getUserInfo(jP.Form["AssignedTo"].val());});

});

 

function getUserInfo(UserName)

{

jP.WebServices.GetUserInfo({userLoginName:UserName});

 

if(jP.WebServices.Result.data.User0 != null)

{

  var user = jP.getUserProfile(jP.WebServices.Result.data.User0.NodeAttr.ID); //Calling getUserProfile with userID from the webservice call

 

//Displaying data

 

  if(!user) {alert("User not found. Please sign in!"); return;}

 

  var out = "";

 

  out += "<b>The current login user account is <font color=red>"+user.Account+"</font></b>"

 

  out += "<table>";

 

  out += "<tr><th>Field Name</th><th>Field Value</th><th>jPoint Code</th></tr>";

 

  $.each(user.Fields, function(i, field){

 

    out += "<tr><td>"+field+"</td><td>"+user[field]+"</td><td>jP.UserProfile."+field+"</td></tr>";

 

  });

 

  out += "</table>";

 

  $("#outdiv").html(out);

}

else

{

  $("#outdiv").html('');

}

}

</script>