Setting Email and LANID fields from People Picker in SP 2013

Forums Classic DFFS Setting Email and LANID fields from People Picker in SP 2013

Viewing 4 reply threads
  • Author
    Posts
    • #15511

      Hi, I’m new to DFFS and am hoping I can move away from InfoPath into this platform. I’m stuck getting some necessary data from the people picker though.

      On my form, I have a people picker called “Requester”. I want to use that to populate fields for Requester Name, Email, and LANID. It was easy to set the rule to populate the name (set the value to {Requester} and done) but I am struggling with how to bring over LAN ID and email address. I saw this but it appears to be for SharePoint 2007/2010. I’m using 2013, and it’s not clear how I’d use that code to populate a field on the form anyhow. Any ideas here?

      Thanks!

    • #15586
      Alexander Bautz
      Keymaster

      Hi,
      Are you populating the field “Requester” with the current user? – if so, you can set properties from the user profile also – look at the help text on the “Set field value” section in the rule. Basically you use these properties in the “value” field:

      // Email
      {userProfile:WorkEmail}
      // Name
      {userProfile:PreferredName}

      Not sure what your “LANID” field is, but if it is in the user profile you can use it.

      Let me know if you need more help.

      Alexander

    • #15606

      Hi Alexander. In our case we can’t assume the current user is the Requester, as often these request are submitted on behalf of a manger one of their staff members. It also would affect the approval flow, since if A submits on behalf of B, B would need to approve it first.

      I am setting the Submitter using {userProfile:WorkEmail} and {userProfile:UserName}. And I’m able to get the Requester’s name and LAN ID via a button on the form with this custom JS:

      On the tab:
      <button type="button" onclick="getRequester()">Get Requester
      
      In Custom JS:
      function getRequester() {
          var RequesterLANID
          var RequesterName
          RequesterLANID = spjs.utility.getFieldValue({"fin":"Requester","delimiter":",","key":"loginName"}).slice(14);
          RequesterName = spjs.utility.getFieldValue({"fin":"Requester","delimiter":",","key":"displayName"});
          setFieldValue("RequesterLANID",RequesterLANID);
          setFieldValue("RequesterName",RequesterName);
      }

      Note that I’d like to get a third value, the email address I can’t find the key value for that, as WorkEmail doesn’t return anything.

      I’d also prefer to not make a user click a button to populate the Requester details. Once they select a name from the people picker it should populate them. But if I try to trigger that function using onclick:

      document.getElementById("Requester_1f4555cf-abb5-46d6-9c90-cf0e0063d350_$ClientPeoplePicker").onchange = function() {getRequester()};

      all it will do it populate the fields with the characters I typed into the people picker, not the actual values.

      Thanks!

    • #15626

      Ok so that turned out to be easier than I thought (caution, noob learning here), I just put my function which I tightened up considerably into a rule where the Requester peoplepicker is changed from initial value and it works. Now if only I could obtain the email address from active directory I’d be completely set to go. Worse case, I can populate that via a workflow.

      `function getRequester() {
      setFieldValue(“RequesterLANID”,spjs.utility.getFieldValue({“fin”:”Requester”,”delimiter”:”,”,”key”:”loginName”}).slice(14));
      setFieldValue(“RequesterName”,spjs.utility.getFieldValue({“fin”:”Requester”,”delimiter”:”,”,”key”:”displayName”}));
      }’

    • #15671
      Alexander Bautz
      Keymaster

      I’m glad you figured it out. You can get the user info from the site collection like this:

      var login = spjs.utility.getFieldValue({"fin":"Requester","delimiter":",","key":"loginName"});
      var ui = spjs.utility.userInfo(login);
      alert(ui.EMail);

      or you can get the user profile like this:

      var login = spjs.utility.getFieldValue({"fin":"Requester","delimiter":",","key":"loginName"});
      var up = spjs.utility.userProfile(login);
      alert(up.WorkEmail);

      Alexander

Viewing 4 reply threads
  • You must be logged in to reply to this topic.