Skip to main content

Search

Concatenate multiple person fields in one

Comments

9 comments

  • RosarioM

    Hello Jan Vanderstappen,

    You need to select Template expression type from dropdown.

    The expression should look like that :
    [[PAD]][[RPAD]][[ServiceDirector]]

     

    Regards

    Rosario Matos

    0
  • JanV

    Hello Rosario,

     

    Thank you for your answer. Unfortunatelly this doesn't work for me:

    The names are glued together and are being resolved as one name.

    This is my formula:

    And this is my column configuration:

     

    Am I missing something?

    0
  • AndrewBerezovskyy2

    Hello Jan Vanderstappen

     

    I prepared calculated value expression code for you.
    Please insert this code as Calculated Expression for Contract owner multi user field

     

    var MULTI_USER_FIELD_NAME = 'Contract owner';
    var UserField1 = [[PAD]];
    var UserField2 = [[RPAD]];
    var UserField3 = [[ServiceDirector]];

    var updateMultiUserFied = function(){
         var multiUserField = jQuery(".ard-formwebpart [title='"+MULTI_USER_FIELD_NAME+"']").find("input[id$='ClientPeoplePicker_EditorInput']").get(0);
         if(multiUserField){
              var loginNames = '';
              
              if(UserField1 && UserField1.Key) loginNames = loginNames + UserField1.Key + ";" ;
              if(UserField2 && UserField2.Key) loginNames = loginNames + UserField2.Key + ";" ;
              if(UserField3 && UserField3.Key) loginNames = loginNames + UserField3.Key + ";" ;
              
              var peoplepicker = SPClientPeoplePicker.PickerObjectFromSubElement(multiUserField);     
              peoplepicker.AddUserKeys(loginNames);
         }
    }     
    setTimeout(updateMultiUserFied,200);
    return ;

     

    Kind Regards
    Andriy Berezovsky

    0
  • JanV

    Thanks Andrew!

    Your code works!

     

    I do feel that this is a lot of code for something small like concatenate people fields. Do you think that a solution like Rosariu mentioned will be available once?

     

    Thanks!

    0
  • JanV

    Hello Andrew,

     

    It seemed to work on the first time but after some testing some bugs occured.

    First of all, when I change a value in the form, the code ran 3 times which occurred in users that where added 3 times.

    For example:

    Pad User, RPAD User, PAD User, RPAD User, PAD User, RPAD User.

    I've been able to work around that by deleting all values in the people picker prior of adding them:

    var peoplepicker = SPClientPeoplePicker.PickerObjectFromSubElement(multiUserField);
    //Remove all existing values
    var allUsers = peoplepicker.GetAllUserInfo();
    allUsers.forEach(function (index) {
    peoplepicker.DeleteProcessedUser(allUsers[index]);
    });
    //Add new values
    peoplepicker.AddUserKeys(loginNames);

     

    The other bug that I noticed is that the code doesn't run when a value of one of the first peoplepickers is emptied. The contract owner field does not get updated. I haven't found a solution for this yet. Do you have something in mind?

    I've tried adding a 'Contract owner = ""' statement in one of the source fields but this gives me an infinite loop.

     

    Thanks for the help!

    0
  • RosarioM

    Hi Jan Vanderstappen

    Support team told me that you overcome this issue, can you share with the Community which steps did you took it.

    Thanks

    Rosario Matos

    0
  • JanV

    Hello Rosario,

     

    The three original people fields are automatically calculated when a certain value is chosen from several dropdowns. I've just made sure that these dropdowns where required and being emptied on the right time.

    By doing that I'm always requiring a user interaction which then calculates the people fields (and thus overwriting the last calculated values).

     

    It's kind off hard to explain but this work around works in my situation.

     

    Either way: It would be nice if you could just concatenate people fields by using PeopleField1 + PeopleField2 or something like that :-)

    0
  • RosarioM

    Hi Jan Vanderstappen

    Thanks for the sharing this.

    Regards

    Rosario Matos

    0
  • Matthias_Walter

    Hi Jan Vanderstappen,

    good idea, can I ask you to add it here Ideas SharePoint Add-Ins and vote for it?

     

    BR Matthias

    0

Please sign in to leave a comment.