Semicolon-plus-space separated value from SPFieldUserMulti

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

Tagged: ,

Viewing 7 reply threads
  • 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

    • #31257
      MikeS
      Participant

      Alexander,

      I’m in need of a similar solution using autocomplete. This is a multi-select requirement where the user can select one or multiple names from a second list. This second list contains names and emails.

      The names and the associated emails are then aggregated and concatenated in two separate fields as follows:

      Names:
      Doe, John; Doe, Jane

      Emails:
      john.doe@foo.com; jane.doe@foo.com

      Numerous attempts so far always result in the message: “You cannot use the ‘setFields’ section in the configuration when you are using the ‘multiselect’ option” error message.

      Thanks,
      Mike

    • #31272
      Alexander Bautz
      Keymaster

      This is unfortunately how it works – the script does not allow you to use the setFields when you use multiselect.

      You might be able to use a cascading dropdown instead? – I answered a similar question and created some custom js to concatenate multiple values in a text field – see if you might be able to use something like this: https://spjsblog.com/forums/topic/combine-selected-cascading-pairs-in-text-fields/

      Alexander

Viewing 7 reply threads
  • You must be logged in to reply to this topic.