Home › Forums › SPJS-Utility › Pull login name from People Picker Field
Tagged: SPJS-Utililty
- This topic has 5 replies, 2 voices, and was last updated 6 years, 1 month ago by Alexander Bautz.
-
AuthorPosts
-
-
August 22, 2018 at 19:32 #21904
Hi –
I was using SPJS-Utility as shown in this post to pull a few fields from a list item that were then used to prepopulate corresponding fields in a new item form. With a recent upgrade of our from SP2010 to SP2013 the prepopulated person fields are no longer working (see attachment). It looks like SP2013 wants either login names or email addresses instead of a lastname, firstname format. Is there a way SPJS Utility can pull either of those formats from a people picker field?
Thanks,
AndrewAttachments:
-
August 22, 2018 at 19:58 #21910
Hi,
Yes, use this format:var loginName = spjs.utility.getFieldValue({"fin":"YourPeoplePicker","key":"loginName"});
This will return an array like this – with only one item if the PP is single choice:
["i:0#.f|membership|username@domain.com"]
Alexander
-
August 22, 2018 at 20:20 #21916
Thanks Alexander! I apologize. I probably didn’t explain enough of what I was doing. I have a URL in a column of List1 that points to a List2 new item form with the ID of the List1 item tacked on the end. On the List2 new form I have DFFS installed with a rule that runs the spjs.utility.queryItems to get certain fields from the item in List1 and drops them into the corresponding fields in the new item form. Am I limited to the firstname, lastname format like that? Relevant code in the List2 new item form is below. Thanks so much for you help!
function clone(){ var cloneid = getParameterByName('cloneid'); var res = spjs.utility.queryItems({ "listName": "List1", "query": "<Where><Eq><FieldRef Name='ID'/><Value Type='Number'>" + cloneid + "</Value></Eq></Where>", "viewFields": ["Title", "PeoplePicker1", "PeoplePicker2", "PCMID"] }); if (res.count > 0) { jQuery.each(res.items, function (index, item) { setFieldValue("Title",item.Title); item.PeoplePicker1 = item.PeoplePicker1.substring(item.PeoplePicker1.indexOf("#")+1); setFieldValue("PeoplePicker1",item.PeoplePicker1); item.PeoplePicker2 = item.PeoplePicker2.substring(item.PeoplePicker2.indexOf("#")+1); setFieldValue("PeoplePicker2",item.PeoplePicker2); setFieldValue("PCMID",item.PCMID); } )} }
-
August 23, 2018 at 16:18 #21923
In this case you only get the userId and the display name back from the query, and must make another call to get the login name. Do it like this:
if(item.PeoplePicker1 !== null){ setFieldValue("PeoplePicker1",spjs.utility.userInfo(item.PeoplePicker1.split(";#")[0]).Name); }
Alexander
-
October 18, 2018 at 17:03 #22537
Alexander —
Thanks for the reply. I’d been moved to a different project for a few months so I didn’t have a chance to test this until today. It worked perfectly!
Thanks again,
Andrew -
October 18, 2018 at 18:31 #22539
Thanks for the feedback – I’m glad it worked.
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.