Semicolon-plus-space separated value from SPFieldUserMulti

Forums Dynamic Forms for SharePoint Semicolon-plus-space separated value from SPFieldUserMulti

Tagged: ,

This topic contains 5 replies, has 2 voices, and was last updated by  Alexander Bautz 2 months, 4 weeks ago.

  • Author
    Posts
  • #25826

    BenR
    Participant

    Alexander,

    Looking for a method to create a semicolon-plus-space separated value from a People Picker Multivalue field. The issue is that my environment uses lastName, firstName format. Leveraging setFieldValue() or Rule-Set field value methods does allow me to move the PP value into a string, but the format looks odd: 1firstName, 1lastName,2firstName, 2lastName (note that the values are separated by a comma).

    If I use a QuickEdit view of the multivalue People Picker and my target string field, and then simply copy from PP to string, the result is 1firstName, 1lastName; 2firstName, 2lastName (note that the values are separated by a semicolon-plus-space).

    Can you suggest a JS method I can use in Custom JS that would emulate the result of QuickEdit copy-n-paste?

    As always, I appreciate your support and efforts!

    R’grds – Ben.
    Reference:
    DFFS frontend: 4.4.3.65 – March 31, 2019
    DFFS frontend CSS: 4.46 / 4.46
    Autocomplete: 1.6.28 – January 12, 2019
    Cascading dropdowns: 3.7.26 – March 31, 2019
    jQuery: 1.12.4
    Lookup: 1.1.16 – March 05, 2019
    Resource management: not loaded
    SPJS-Utility: 1.332 – March 05, 2019
    vLookup: 2.2.129 – March 07, 2019

  • #25831

    Alexander Bautz
    Keymaster

    Hi,
    You can use an array like this if you set the value with setFieldValue:

    setFieldValue("PeoplePicker1",["User, Test"]);

    In general, using the login name is preferred over display name when setting the value, but if you don’t have the login name available you would need to run some custom js to get it based on the display name or ID of the user.

    Alexander

  • #25837

    BenR
    Participant

    Alexander,

    Sorry – I have been unclear… The problem is in the formatting of the result as a string.

    In this example, the resultant string is correct – but formatted poorly:

    setFieldValue("mySPFieldText",getFieldValue("mySPFieldUserMulti");

    If mySPFieldUserMulti contains two names, that value is set to the string field mySPFieldText separated by a comma and is where the poor formatting comes in. Like this: mySPFieldUserMulti contains two names:

    • Doe, Jane
    • Public, John

    The result in mySPFieldText will be:

    Doe, Jane,Public, John

    Note that there is no space after the comma between Jane and Public. This is the same result if I use a rule to set the field value.

    What I would like to achieve is the result string to be formatted as

    Doe, Jane; Public, John

    Note that there is semicolon-and-space used to separate the two values.

    Thank you for your consideration.

    R’grds – Ben.

  • #25839

    Alexander Bautz
    Keymaster

    Hi,
    When you use getFieldValue on a multichoice field, the returned value is an array. This means you can set the value like this:

    setFieldValue("mySPFieldText",getFieldValue("mySPFieldUserMulti").join("; "));

    Alexander

  • #25843

    BenR
    Participant

    Alexander,

    Thank you – you never disappoint! This method is exactly what I needed, and a good lesson. As always, I appreciate your support and efforts!

    R’grds – Ben.

  • #25845

    Alexander Bautz
    Keymaster

    Thanks, I’m glad it worked!

    Alexander

You must be logged in to reply to this topic.