1

I'm using the following code in a webpart JSLink to pull user information from a Person and Groups Field:

    (function () {

    var overrideCtx = {};

    overrideCtx.Templates = {};

    overrideCtx.Templates.Item = itemOverrideFunc;

     overrideCtx.BaseViewID = 1;

    overrideCtx.ListTemplateType = 100;

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
  })(); 

function itemOverrideFunc(ctx) 
{
 var users = ctx.CurrentItem["People"];

  for(i = 0; i < users.length; i++){

       var curUserName = users[i].title;

       // access department information of user or group
        var curUserDepartment = users[i].department;

        // access email address of user or group
        var curUserEmail = users[i].email;

       // access job title of user or group
       var curUserJobTitle = users[i].jobtitle;

       // access user picture url
       // contains the picture form the user profile service
       var curUserPicture = users[i].picture;

    }
 var ret = "<div class=\"divname1\" style=\"margin-bottom:20px;clear:both;\">"
    ret += "<div class=\"divname2\" style=\"float:left;width:90px\">"
    ret += "<img src=\"" + curUserPicture + "\"\>" + "</div>" 
    ret += "<div class=\"divname3\" style=\"float:left;width:500px;\">"
    ret += "<h2 style=\"margin-bottom:0px;padding-bottom:0px\">" + curUserName + "</h2><a href=\"mailto=" + curUserEmail + "\">" + curUserEmail +   "</a><br/>" + curUserJobTitle + "<br/>" + curUserDepartment + "<br/>" + ctx.CurrentItem.About_x0020_Me + ""
    ret += "</div><div style=\"clear:both\"></div>";
    ret += "</div>";

    return ret;

    }

Everything is working great except the curUserJobTitle which returns an "undefined" error.

Any ideas?

6
  • Try users[i].title instead of jobtitle. Aug 17, 2016 at 20:28
  • 1
    users[i].title actually returns the name of the person. I've updated my code above.
    – Maureen
    Aug 18, 2016 at 18:07
  • Good point, scratch that :) Aug 18, 2016 at 18:23
  • Have you checked whether the "Title" field is filled out in the hidden users list? sharepoint/sitecollection/_catalogs/users/detail.aspx
    – Erin L
    Aug 18, 2016 at 18:51
  • Hi Erin, yes I have. There are three columns in my hidden User Information List. The Title column is filled out for the users. In my User Profiles in Central Administration there is actually a Title field and a Job Title field. I have tried many combinations of users[i].sps-jobtitle, users[i].ows_jobtitle etc with no luck.
    – Maureen
    Aug 19, 2016 at 12:38

1 Answer 1

2

I figured it out. This was a problem of case. The correct line for Job Title is

var curUserJobTitle = users[i].jobTitle;

For those interested I found the correct property name by adding the following

var keyNames = Object.keys(users[i]);
for (b = 0; b < keyNames.length; b++) {
  console.log(keyNames[b]);

just under

for(i = 0; i < users.length; i++){

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.