June 20, 2019 at 13:52 #25826
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.
DFFS frontend: 188.8.131.52 – 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
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
June 20, 2019 at 15:59 #25831
You can use an array like this if you set the value with setFieldValue:
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.
June 20, 2019 at 17:18 #25837
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:
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.
June 20, 2019 at 22:32 #25839
When you use getFieldValue on a multichoice field, the returned value is an array. This means you can set the value like this:
June 21, 2019 at 14:12 #25843
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.
June 21, 2019 at 16:12 #25845
Thanks, I’m glad it worked!
August 18, 2020 at 23:57 #31257MikeSParticipant
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:
Doe, John; Doe, Jane
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.
August 19, 2020 at 22:19 #31272
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/
- You must be logged in to reply to this topic.