SharePoint JavaScripts

  • Home
  • Products
    • Classic DFFS
      • Product page / buy a license
      • Installation manual
      • User manual
      • DFFS Plugins
        • vLookup for SharePoint
          • Product page
          • User manual
          • Setup example
          • Change log (SP2010 and SP2013)
          • Change log (SP2007)
          • Forum
        • SPJS-Cascading Dropdowns
        • SPJS-Autocomplete
        • SPJS-Lookup
        • Other plugins
      • Styling forms
      • Forum
      • Change log
    • Modern DFFS
    • SPJS Charts for SharePoint
      • Product page / buy a license
      • User manual
      • SPJS Charts – Custom Datasource
      • v6 Change log
      • v7 Change log
    • CommentBox for SharePoint
      • Product page / buy a license
      • v2.x Installation manual
      • v3.x Installation manual
      • v2.x Change log
      • v3.x Change log
    • Modern CEWP
  • Partners
    • Partners
    • Partner registration
  • Forums
  • Archives
  • Contact
  • Copyright and disclaimer

Pull user info from a people picker

Home › Forums › Classic DFFS › Pull user info from a people picker

Tagged: DFFS, user info

  • This topic has 25 replies, 7 voices, and was last updated 4 years, 9 months ago by Alexander Bautz.
Viewing 25 reply threads
  • Author
    Posts
    • January 30, 2016 at 09:22 #10080
      Alexander Bautz
      Keymaster

        This code example show how to pull user info from a people picker (single or multi select), and return the user info – either from the SharePoint userinfo list, or from the SharePoint userprofile service (not available in SP Foundation).

        The code is written for user withe DFFS – in the Custom JS textarea.

        // Use this code in NewForm or EditForm
        $.each(spjs.utility.getFieldValue({"fin":"PeoplePicker1","key":"loginName"}),function(i,login){
        var ppData = spjs.utility.userInfo(login);
        console.log(ppData);
        // User profile is not available in SP Foundation
        var userProfile = spjs.utility.userProfile(login);
        console.log(userProfile);
        });
        
        // Use this in DispForm
        $.each(spjs.dffs.beforeProperties["PeoplePicker1_ID"],function(i,userId){
        var ppData = spjs.utility.userInfo(userId);
        console.log(ppData);
        // User profile is not available in SP Foundation
        var userProfile = spjs.utility.userProfile(ppData.Name);
        console.log(userProfile);
        });

        Replace “PeoplePicker1” with your FieldInternalName.

        Alexander

      • July 27, 2017 at 12:45 #17488
        Brett Ross
        Participant

          I’m not a programmer, so I need a little more instruction. I’ve added this to the Custom JS textarea and changed PeoplePicker1 to my field name. But how do I tell it what field to populate? And how do I change it if I want to pull in other properties like the phone number?

          • This reply was modified 7 years, 9 months ago by Brett Ross.
        • July 27, 2017 at 23:21 #17508
          Alexander Bautz
          Keymaster

            Hi,
            Basically you would add a line below the console.log(userProfile) line like this:

            setFieldValue("TheNameOfYourField",userProfile.name_of_property);

            To know which properties you have to select from, open the dev tools (hit F12) and select “Console”. Expand the logged profile object and look at the available properties.

            Please note that the console.log line should NOT be active in production – it’s just to show the profile and the properties.

            Let me know how this works out.

            Alexander

          • September 5, 2017 at 19:42 #18019
            George Hite
            Participant

              Sorry for the dumb question but I typed in the Custom JS the exact Function for new form as you displayed above and replacing PeoplePicker1 with my Internal Field Name… The console log only displays the DFFS load time tracker. And if I add names it displays Empty string. I don’t know what I’m doing wrong…

              Attachments:
              1. nothing.jpg

              2. nothing2.jpg

            • September 6, 2017 at 16:24 #18032
              George Hite
              Participant

                I forgot to show the code I put into custom JS tab on DFFS… here it is.

                Attachments:
                1. CAPA_-_New_Item_-_2017-09-06_10.22.40.png

              • September 6, 2017 at 18:51 #18046
                Alexander Bautz
                Keymaster

                  Hi,
                  My example for NewForm could have been better as this code will run as the form loads – before you have set anything in the people picker.

                  If you are trying to pull info from the pp to write to another field, you must wrap the code in a named function and set up a trigger on form save to call this function.

                  Alexander

                • September 6, 2017 at 18:57 #18049
                  George Hite
                  Participant

                    I think I figured it out… in the Misc tab on DFFS section Defer loading of DFFS I had to set the time their… I set it to 300ms don’t know if that’s too much will test by reducing…

                  • January 7, 2018 at 17:03 #19218
                    Brett Ross
                    Participant

                      I’ve had this working since July, and all of a sudden now, it’s no longer working. I’m pulling in the Contract Manager’s work phone number from the user profiles. Here’s my code.

                      $.each(spjs.utility.getFieldValue({“fin”:”Contract_x0020_Manager”,”key”:”loginName”}),function(i,login){
                      var ppData = spjs.utility.userInfo(login);
                      console.log(ppData);

                      var userProfile = spjs.utility.userProfile(login);
                      console.log(userProfile);
                      setFieldValue(“CM_x0020_Phone_x0020_Number”,userProfile.WorkPhone);
                      });

                      I’ve also tried wrapping it in a function, then writing a rule that says, any time the Contract Manager field changes, run the function. But that doesn’t work either.

                      function PopulatePhone ()
                      {
                      $.each(spjs.utility.getFieldValue({“fin”:”Contract_x0020_Manager”,”key”:”loginName”}),function(i,login){
                      var ppData = spjs.utility.userInfo(login);
                      console.log(ppData);
                      // User profile is not available in SP Foundation
                      var userProfile = spjs.utility.userProfile(login);
                      console.log(userProfile);
                      setFieldValue(“CM_x0020_Phone_x0020_Number”,userProfile.name_of_property);
                      });
                      }

                    • January 7, 2018 at 17:17 #19220
                      Brett Ross
                      Participant

                        Nevermind. I see my mistake.

                      • January 7, 2018 at 23:49 #19226
                        Alexander Bautz
                        Keymaster

                          I’m glad you figured it out.

                          Alexander

                        • May 17, 2018 at 20:44 #20923
                          Notrega
                          Participant

                            Andrew – I work with Brett who responded above and she can’t figure out where I am screwing up. This WAS working a few days ago and I don’t know what kinked it up.

                            I have a people picker that is only entered on the NewForm and I want to pull out LastName & FirstName into their own fields. I cannot get LastName FirstName fields to display in the DispForm. They display fine on the EditForm.

                            Do I need code on all three forms or just one?

                            This is the code I am using on the NewForm and EditForm

                            function PopulateLastFirst ()
                             {
                            //Pull in Last Name and First Name from Employee field.
                            $.each(spjs.utility.getFieldValue({"fin":"Employee","key":"loginName"}),function(i,login){
                                var ppData = spjs.utility.userInfo(login);
                                console.log(ppData);
                                // User profile is not available in SP Foundation
                                var userProfile = spjs.utility.userProfile(login);
                                console.log(userProfile);
                                setFieldValue("Last_x0020_Name",userProfile.LastName); 
                                setFieldValue("First_x0020_Name",userProfile.FirstName); 
                            });
                            }

                            This is the code I have on the DispForm

                            function PopulateLastFirst ()
                            {
                            $.each(spjs.dffs.beforeProperties["Employee"],function(i,userId){
                            var ppData = spjs.utility.userInfo(userId);
                            console.log(ppData);
                            // User profile is not available in SP Foundation
                            var userProfile = spjs.utility.userProfile(ppData.Name);
                            console.log(userProfile);
                                setFieldValue("Last_x0020_Name",userProfile.LastName); 
                                setFieldValue("First_x0020_Name",userProfile.FirstName); 
                            });
                            }

                            I even tried this on advice from Brett… on the DispForm

                            function PopulateLastFirst ()
                            {
                            $.each(spjs.dffs.beforeProperties["Employee"],function(i,userId){
                            var ppData = spjs.utility.userInfo(userId);
                            console.log(ppData);
                            // User profile is not available in SP Foundation
                            var userProfile = spjs.utility.userProfile(ppData.Name);
                            console.log(userProfile);
                            
                            });
                            }

                            Any help you could give would be much appreciated.

                            • This reply was modified 7 years ago by Notrega.
                            • This reply was modified 7 years ago by Notrega.
                          • May 17, 2018 at 21:02 #20927
                            Notrega
                            Participant

                              I am an idiot… I got it to work

                            • May 17, 2018 at 23:03 #20931
                              Alexander Bautz
                              Keymaster

                                I’m glad you figured it out!

                                Best regards,
                                Alexander

                              • October 22, 2018 at 12:57 #22586
                                Ayanda Makhathini
                                Participant

                                  Hi Alex

                                  My code is similar(if not the same) as Notrega , but unfortunately he did not post what he did to solve his problem , I cant seem to find the difference between your JS above and his/hers .

                                  I’m trying to populate the users title and SipAddress in the respective fields but when I save on edit and New form i doesnt seem to get the information of the user. I have the rule to trigger the function on save but it still get nothing.

                                  Can you help me?

                                  (I did remove _ID from DispForm but it still didnt work)

                                  Attachments:
                                  1. Screenshot_66.png

                                  2. Screenshot_67.png

                                • October 22, 2018 at 18:34 #22592
                                  Alexander Bautz
                                  Keymaster

                                    Hi,
                                    Do you see the output in the console (you must hit F12 and select Console) when running the code?

                                    Please note that the console.log lines must not be in the production code – these are for debugging only.

                                    Alexander

                                  • October 23, 2018 at 14:28 #22598
                                    Ayanda Makhathini
                                    Participant

                                      Hi Alex

                                      my code is showing undefined. Even when i test the spjs.utility.userInfo(login); section which i think is to get the user details in the people picker its returning undefined

                                      I also have triggered the function on save in the rules.

                                      fieldInternalName = SP_x0020_Email_x0020_Valid

                                      Thanks

                                      Attachments:
                                      1. Screenshot_70.png

                                      2. Screenshot_71.png

                                    • October 23, 2018 at 15:11 #22602
                                      Ayanda Makhathini
                                      Participant

                                        Hi Alex

                                        I found the issue it was my JS syntax. my query is trying to set (userprofile) that hasnt been set hence undefined.

                                        function populateSPNameAndEmail()
                                        {
                                        $.each(spjs.utility.getFieldValue({“fin”:”SP_x0020_Email_x0020_Valid”,”key”:”loginName”}),function(i,login){
                                        var ppData = spjs.utility.userInfo(login);
                                        console.log(ppData);
                                        setFieldValue(“Full_x0020_Name”,ppData.Title);
                                        setFieldValue(“Email_x0020_Address”,ppData.SipAddress);
                                        });
                                        }

                                        I had the wrong field aswell in the above code for SipAdress.
                                        Thank you for the jQuery its very useful

                                      • October 23, 2018 at 15:19 #22606
                                        Alexander Bautz
                                        Keymaster

                                          I’m glad you figured it out.

                                          Alexander

                                        • April 3, 2019 at 17:03 #24649
                                          David Jeremias
                                          Participant

                                            Hey Alexander,

                                            Can this be done in the display form with a multi-person field (for example: to display the loginName of each person in a single multi-person field)?

                                            Thanks!
                                            David

                                          • April 3, 2019 at 22:15 #24661
                                            Alexander Bautz
                                            Keymaster

                                              Hi,
                                              You can use a snippet like this to get the users from a multichoice (or single choice people picker) and get their login name:

                                              var userLoginNames = [];
                                              jQuery.each(spjs.dffs.beforeProperties.PeoplePicker1_ID,function(i,id){
                                              	userLoginNames.push(spjs.utility.userInfo(id).Name);
                                              });
                                              console.log(userLoginNames);

                                              Change “PeoplePicker1” with your people picker internal name.

                                              Alexander

                                              • This reply was modified 6 years, 1 month ago by Alexander Bautz.
                                            • August 18, 2020 at 13:51 #31232
                                              BenR
                                              Participant

                                                Alexander,

                                                I hope you are well and staying safe.

                                                I have applied this method to retrieve additional information from eight People Picker fields (all single selection fields). I have triggered this function to On-Save rules in both NewItem and EditItem forms. However, I find that it doesn’t always work, where none of the destination fields are populated – this is in 15 of 100 sampled records.

                                                I cannot find a pattern across the 15 failed records

                                                • Some created via NewItem, some subsequently edited in EditItem
                                                • Different users either create or edit failed records
                                                • My firm uses IE, Chrome, and Firefox – but I can’t tell what my users use, but my tests show all three browsers work

                                                Is there something in my code that you see that could cause this 15% failure rate?

                                                
                                                
                                                function acquireRoleDetail(){
                                                 jQuery.each(spjs.utility.getFieldValue({"fin":"Compass_x0020_Delivery_x0020_Man","key":"loginName"}),function(i,login){
                                                 var ppData = spjs.utility.userInfo(login);
                                                  setFieldValue("DeliveryManagerSIP",ppData.SipAddress);
                                                  setFieldValue("DeliveryManagerSID",ppData.Name.slice(-7).toUpperCase());
                                                 });
                                                 jQuery.each(spjs.utility.getFieldValue({"fin":"ExecutiveSponsor","key":"loginName"}),function(i,login){
                                                 var ppData = spjs.utility.userInfo(login);
                                                  setFieldValue("ExecutiveSponsorSIP",ppData.SipAddress);
                                                  setFieldValue("ExecutiveSponsorSID",ppData.Name.slice(-7).toUpperCase());
                                                 });
                                                  jQuery.each(spjs.utility.getFieldValue({"fin":"FinalApprover","key":"loginName"}),function(i,login){
                                                 var ppData = spjs.utility.userInfo(login);
                                                  setFieldValue("FinalApproverSIP",ppData.SipAddress);
                                                  setFieldValue("FinalApproverSID",ppData.Name.slice(-7).toUpperCase());
                                                 });
                                                  jQuery.each(spjs.utility.getFieldValue({"fin":"FinanceManager","key":"loginName"}),function(i,login){
                                                 var ppData = spjs.utility.userInfo(login);
                                                  setFieldValue("FinanceManagerSIP",ppData.SipAddress);
                                                  setFieldValue("FinanceManagerSID",ppData.Name.slice(-7).toUpperCase());
                                                 });
                                                  jQuery.each(spjs.utility.getFieldValue({"fin":"LegalContact","key":"loginName"}),function(i,login){
                                                 var ppData = spjs.utility.userInfo(login);
                                                  setFieldValue("LegalContactSIP",ppData.SipAddress);
                                                  setFieldValue("LegalContactSID",ppData.Name.slice(-7).toUpperCase());
                                                 });
                                                  jQuery.each(spjs.utility.getFieldValue({"fin":"SourcingCategoryDirector","key":"loginName"}),function(i,login){
                                                 var ppData = spjs.utility.userInfo(login);
                                                  setFieldValue("SourcingCategoryDirectorSIP",ppData.SipAddress);
                                                  setFieldValue("SourcingCategoryDirectorSID",ppData.Name.slice(-7).toUpperCase());
                                                 });
                                                  jQuery.each(spjs.utility.getFieldValue({"fin":"SourcingManager","key":"loginName"}),function(i,login){
                                                 var ppData = spjs.utility.userInfo(login);
                                                  setFieldValue("SourcingCategoryManagerSIP",ppData.SipAddress);
                                                  setFieldValue("SourcingCategoryManagerSID",ppData.Name.slice(-7).toUpperCase());
                                                 });
                                                  jQuery.each(spjs.utility.getFieldValue({"fin":"VendorManager","key":"loginName"}),function(i,login){
                                                 var ppData = spjs.utility.userInfo(login);
                                                  setFieldValue("VendorManagerSIP",ppData.SipAddress);
                                                  setFieldValue("VendorManagerSID",ppData.Name.slice(-7).toUpperCase());
                                                 });
                                                }

                                                As always, your support and efforts are greatly appreciated!

                                                R’grds – Ben.
                                                Reference:
                                                Version information
                                                Custom DFFS-folder: DFFS_v4.4.5.4_2020-07-04
                                                DFFS Loader: v2
                                                DFFS frontend: 4.4.5.4 – July 04, 2020
                                                DFFS frontend CSS: 4.61 / 4.61
                                                Autocomplete: 1.6.49 – June 28, 2020
                                                Cascading dropdowns: 3.7.40 – June 1, 2020
                                                jQuery: 1.12.4
                                                Lookup: 1.1.20 – March 10, 2020
                                                Resource management: 2.4.5 – August 29, 2019
                                                SPJS-Utility: 1.348 – June 28, 2020
                                                vLookup: 2.2.156 – June 28, 2020

                                              • August 18, 2020 at 15:13 #31236
                                                BenR
                                                Participant

                                                  Alexander,

                                                  As my solution was to replicate the provided code eight times to address eight People Picker fields, plus the symptom is a failure of the bulk function, I’ve broken the bulk function into eight discreet functions…

                                                  I hope to see a possible improvement, and am gathering statistics.

                                                  R’grds – Ben.

                                                • August 18, 2020 at 19:45 #31244
                                                  Alexander Bautz
                                                  Keymaster

                                                    It’s hard to tell what could cause it – as long as they don’t use quick edit / datasheet to edit.

                                                    Let me know if you find out anything from your statistics and I’ll do my best to help.

                                                    Alexander

                                                  • August 20, 2020 at 18:03 #31289
                                                    BenR
                                                    Participant

                                                      Alexander,

                                                      I’ve gathered more statistics to judge effectiveness of my prior vs. current JS method…

                                                      Assuming that a given function will never succeed 100% of the time, grouping eight operations into one function produced a 15% failure rate across 100 invocations (one per record).

                                                      However, by breaking the eight operations into eight discrete functions each invoked once per record, the failure rate drops dramatically. The next 50 records (8×50=400 invocations) resulted in only four failures, or .01% – which is totally acceptable in my application.

                                                      Thank you for your support, I think I have a solution!

                                                      R’grds – Ben.

                                                    • August 20, 2020 at 18:46 #31291
                                                      BenR
                                                      Participant

                                                        Whoops! I embarrass myself – Err: .01% should be 1%.

                                                      • August 20, 2020 at 21:42 #31294
                                                        Alexander Bautz
                                                        Keymaster

                                                          I’m glad you got it running a bit smoother.

                                                          Alexander

                                                      • Author
                                                        Posts
                                                      Viewing 25 reply threads
                                                      • You must be logged in to reply to this topic.
                                                      Log In
                                                      Your cart is empty
                                                      Are you happy with the support?
                                                      I don't currently charge anything for support, but I spend a lot of time supporting both paid and free solutions. I appreciate it if you put some money in my piggy bank!
                                                      Icon by mynamepong from www.flaticon.com
                                                      Log in

                                                      Recent Topics

                                                      • Realted items enabled? by Wendi Watson
                                                        1 day, 1 hour ago
                                                      • DFSS Send email – deprecated soon? by Jon Whisman
                                                        16 hours, 8 minutes ago
                                                      • Modern CEWP – Hide or remove Saturday and Sunday from List Calendar View by Wayne Thompson
                                                        6 days, 7 hours ago
                                                      • Modern DFFS v1.1.12.0 has been released by Alexander Bautz
                                                        1 week, 3 days ago
                                                      • Hide or remove Saturday and Sunday from List Calendar View by Wayne Thompson
                                                        2 weeks, 2 days ago
                                                      • Modern DFFS v1.1.11.0 has been released by Alexander Bautz
                                                        2 weeks, 2 days ago
                                                      • Modern DFFS v1.1.10.0 has been released by Alexander Bautz
                                                        2 weeks, 4 days ago
                                                      • Install on Parent & Subsite + Saving doesn’t leave form by Jonathan Stamper
                                                        2 weeks, 1 day ago
                                                      • Modern DFFS v1.1.9.0 has been released by Alexander Bautz
                                                        3 weeks, 3 days ago
                                                      • Modern DFFS v1.1.8.0 has been released by Alexander Bautz
                                                        1 month ago

                                                      Recent Replies

                                                      • Alexander Bautz on DFSS Send email – deprecated soon? 16 hours, 8 minutes ago
                                                      • Alexander Bautz on Realted items enabled? 1 day, 1 hour ago
                                                      • Alexander Bautz on DFSS Send email – deprecated soon? 1 day, 1 hour ago
                                                      • Wendi Watson on Realted items enabled? 1 day, 4 hours ago
                                                      • Alexander Bautz on Realted items enabled? 1 day, 4 hours ago

                                                      Recent Posts

                                                      • Modern DFFS updated with new installation method
                                                        by Alexander Bautz
                                                        March 2, 2025
                                                      • Modern DFFS v1.0.70.0 has been released
                                                        by Alexander Bautz
                                                        October 13, 2024
                                                      • Modern DFFS v1.0.68.0 has been released
                                                        by Alexander Bautz
                                                        September 15, 2024
                                                      • Modern DFFS v1.0.67.0 has been released
                                                        by Alexander Bautz
                                                        September 12, 2024
                                                      • Modern DFFS v1.0.66.0 has been released
                                                        by Alexander Bautz
                                                        September 4, 2024

                                                      Forums

                                                      • General discussion
                                                      • Modern CEWP
                                                      • Modern DFFS
                                                      • Cascading dropdowns
                                                      • SPJS-Lookup
                                                      • Classic DFFS
                                                      • vLooup for SharePoint
                                                      • SPJS Charts for SharePoint
                                                      • Comment box for SharePoint
                                                      • Autocomplete
                                                      • SPJS-Utility
                                                      • Requests

                                                      Search Forums

                                                      Copyright © All Rights Reserved.
                                                      • About the solutions
                                                      • Archives
                                                      • Classic DFFS
                                                        • DFFS: Installation manual
                                                        • DFFS: Privacy Policy
                                                        • DFFS: Styling
                                                        • DFFS: User manual
                                                        • DFFS and plugins: Change log
                                                          • dffs-change-log-archive
                                                        • DFFS Plugins
                                                          • SPJS-Autocomplete
                                                          • SPJS-Cascading dropdowns
                                                          • SPJS-Lookup
                                                      • CommentBox for SharePoint
                                                        • CommentBox Change log
                                                        • Commentbox v3.x change log
                                                        • Installation manual
                                                        • Installation manual v3
                                                      • Contact
                                                      • Copyright and disclaimer
                                                      • Forums
                                                      • General tips
                                                      • Home
                                                      • License types and Partner program
                                                      • Modern CEWP by SPJS
                                                      • Obtain License Code
                                                        • CommentBoxForSharePoint
                                                      • Partner registration
                                                      • Partners
                                                      • SPJS Charts for SharePoint
                                                        • SPJS Charts for SharePoint user manual
                                                        • SPJS Charts for SharePoint v7: Change log
                                                        • SPJS Charts for SharePoint: Change log
                                                        • Using custom datasource in SPJS Charts v7
                                                      • Thank you!
                                                      • vLookup for SharePoint
                                                        • vLookup Change log
                                                        • vLookup setup example for SP 2010 and 2013
                                                        • vlookup-2007-change-log/
                                                        • vLookup: User manual