AnsweredAssumed Answered

How to use the UserProfileLookup on multiple names in people picker

Question asked by sarahk on Oct 5, 2015
Latest reply on Aug 23, 2018 by bimi82

Hi, I am using a people picker control which can have between 0 and 3 people added to it.


I then want to lookup up some info on each of the added names using the userProfileLookup in a calculated field.


The code below works fine so long as I add more than one name. When I only add one name, I don't get anything.

pSP1 is the name of people picker control.


first person:  userProfileLookup(pSP1[0],"WorkEmail") 

second person: userProfileLookup(pSP1[1],"WorkEmail") 

second person: userProfileLookup(pSP1[2],"WorkEmail") 


So I try to test if there has been only one person added with the following:

if( length(pSP1[0]) < 2, userProfileLookup(pSP1,"WorkEmail"), userProfileLookup(pSP1[0],"WorkEmail")  ) )

and I get the following error message:


Ok, so it doesn't like trying to get the length of something that doesn't exist, so I try add a condition for if the people picker is empty:

if(isNullOrEmpty(pSP1)  ,"", if( length(pSP1[0]) < 2, userProfileLookup(pSP1,"WorkEmail"), userProfileLookup(pSP1[0],"WorkEmail")  ) )


However I still get the same error - somehow even though the length function is in the "else" part of the if function, it seems to be always calculated.


An alternative I tried, gets me the email when only one name is added, but when i add a second name I get #Value! for the first person's email.

if( startsWith(pSP1,"[") , userProfileLookup(pSP1[0],"WorkEmail"), userProfileLookup(pSP1,"WorkEmail")  )


(testing if it starts with '[' should tell me whether there is an array here (meaning more than one person) or it has just returned a single value)


Any help in how to get these working would be great.