Solved

Way to remove the square brackets and quotation marks from a multiple choice list?

  • 17 May 2019
  • 9 replies
  • 269 views

Badge +4

Hey there,

I have been trying to write multiple choice fields to a generated document and I just wanted to know if there was a clean way of using regular expression or any other recommended action to remove the square brackets and quotation marks?

I have attached what the output from the multiple choice option looks like in the document.

2180i53AFCB4FB021D4A7.jpg

icon

Best answer by burked 21 May 2019, 18:00

View original

9 replies

Userlevel 5
Badge +8

The multiple choice action is going to function as a collection, so it will output the information in this format.  The quickest way to do this will be using a Regex Replace action. One note, you will need to create an empty text variable for the replacement text (go to variables, create variable and leave default value for this variable blank).  

 

From there you will configure the action like below:

The 'Input Text' will be the choice control. 

The pattern will be formatted like below:

([)|("")|(])

The replacement text will be the empty variable I created (named blank)

The 'Store Results in' will be a separate text variable that can then be used in your workflow. 

 

Here is the output from my log to instance details (showing pre-regex and post-regex):

 

 

Badge +4
Hey Burked,
This is perfect! Thank you for putting the time and effort into that detailed response.

@burked 


 


Is there a way of doing this in Nintex Forms for Office 365 using replace and possibly adding a line break instead of the comma?

Userlevel 5
Badge +8

Hi @ChetChudasamaTS ,


 


This is definitely possible.  I configured my form with a Choice Control (multiple-selection), provided the control with the name Multi Choice, along with a calculated value control:


 



 


I configured the calculated value control with the formula below (replace MULTI-SELECT_NAMED_CONTROL with the named control reference of your choice control):


 


replace(replace(MULTI-SELECT_NAMED_CONTROL, "([)|(])", ""), ",", "<p>")

I also configured the calculated value control to resize at runtime so it will expand as we have more selections. It's configured like below: 


 



 


When the user interacts with the form, it will look like this:


 


Hi @burked,


 


Thanks for all your help so far, I got a further question regarding the formula please, Is there a way to only return the first value for the array?


 


I have a repeating table of destination cities and use the formula


replace(replace(parseLookup(CityField), "([)|(])", ""), ",", "; ")


to return for example "London; New York; Geneva:


 


Now how do I get it to only return London in a separate calculated field - is there a way to replace everything after and including the first semicolon; so the output would be just London??

Userlevel 2
Badge +6

@burked I must be doing something wrong somewhere. I've copied your solution precisely (or so I believe) but it's not working. In the Input text field, I have inserted the collection variable from the Start event. Then I've followed your instructions for the other fields. My Replacement text is a blank variable I created, called Reformatted selections. Then I'm storing results in another variable called Choices for email (because I want to include the selections in an email).


Based on my instance details, my problem seems to be in the Reformatted selections value: it remains blank.


Here, the Choices made are the selections from the multiple choice field, Reformatted is the reformatted selections variable, and Choices is the Choices for email variable.



The only difference I see between my action and the one in the solution is that the Input text value in the solution is showing with a Collection icon while mine just has the usual "X" icon. But I thought this might just be the result of a change made in NWC since the solution was posted nearly two years ago. If not, I don't see where I would get that Collection variable.


Anyway, any help (from anyone) is appreciated!

Userlevel 5
Badge +8

Hi David,


 


The 'Store Results in' option is writing the Regex result back formatted as a collection, so you have two options.


 


1) You can use the 'Store First Result in' drop down and put your text variable there. This should get the value you're looking for.


2) You can use a 'Get Item From Collection' action to retrieve the results. You shouldn't need to do this though, as option one should be clean.


 


As far as the look of the variable, it has changed a bit on the icons over the last 2 years. With Start Forms being treated as objects now, the variables have gotten an update for the look and feel.


 


Hope this helps!

Userlevel 2
Badge +6

@burked Thanks for such a quick response! Yep, I did as you suggested and that worked a treat (as the Brits say). Much obliged!

Userlevel 2
Badge +6

This is pretty nitpicky, but it seems that NWC no longer puts a space after the comma when listing items in a collection. I know nothing about .net construction, and reading about it hasn't been terribly helpful so far (lol), so how would I format the pattern to not only eliminate the brackets and quotation marks, but to add a space after each comma? Right now my result looks like this:


Firstname Lastname,Firstname Lastname,Firstname Lastname


So I need the extra bit of code to put a space after each comma. This is not a big deal, but it just ... bothers me. 😁

Reply