I have a checkbox with the following options
Blue (BL)
Red (RD)
Magenta (MG)
Green (GN)
The output I want is BL,RD,MG,GN
So, I tried using this script:
findPatternIgnoreCase(%{19401},"BL|RD|MG|GN"
It is not working unfortunately. Help!!!
what kind of field type is your target field? If you try to copy the field values to a text field, it's as simple as just using the field code - in your case %{19401}.
What are you trying to implement by using findPatternIgnoreCase?
Do you want to return a list of all available options or only the ones checked?
Best regards,
Thorsten
The target field is a Text Field, Single Line.
What I'm getting when I just parse the field is Blue (BL),Red (RD),Magenta (MG),Green (GN) but what I want displayed is BL,RD,MG,GN.
That's why I'm attempting findPatternIgnoreCase but can't really get it to work.
Any other options we can use to get the desired output?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
since you don't want to return the options as is, but are trying to manipulate those values, your expression has to be a litte more elaborate:
toString(textOnStringList(toStringList(%{19401}, ","), substring(^%,length(^%)-3,length(^%)-1)))
In short, the expression iterates over your options, cuts away the first n characters including the bracket as well as the last bracket and then rebuilds a new list with the returned values. If all your options follow the same syntax, this expression should do the trick.
Best,
Thorsten
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Cool! Can I set a variable for it? or should I just add it in my concatenated text? I would prefer the cleaner one of course!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dissecting (since I'm not really good at programming :(] )
19401 is a checklist with content checked equals to Blue (BL),Red (RD),Magenta (MG),Green (GN)
%19401 would return Blue (BL),Red (RD),Magenta (MG),Green (GN)
toStringList(%{19401},",") would return ["Blue (BL)","Red (RD)","Magenta (MG)","Green (GN)"]
Setting the above to... say... LST
toString(LST, substring(^%,length(^%)-3,length(^%)-1)) essentially cleans it up.
Uhm... how did ^% get the correct integer? Really sorry. And I would appreciate the walkthrough! I'm sure it would also be helpful to the community.
And the code works perfectly! Just want to understand it more. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
^% is a placeholder used by the textOnStringList function. In short, it is used to iterate over each element of the list you created before:
["Blue (BL)","Red (RD)","Magenta (MG)","Green (GN)"]
So with the given list of four elements, the iteration will be done four times and on the first run, ^% will represent "Blue (BL)" and so on.
Since your options all follow the same composition we can then parse those elements by cutting those two characters between the brackets. We're doing so by referencing "get total string length of this option and substract 3" as the start and "get total string length of this option and subtract 1" as the end index.
Obviously, this only works while only having two characters in between the brackets.
Hope this answer helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually, you won't even need the paramters in your toStringList expression.
toString(textOnStringList(toStringList(%{19401}), substring(^%,length(^%)-3,length(^%)-1)))
Should be sufficient as well.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok. I'm having difficulty coding for three letter codes now. Can you give me a script if the choices are as follows?
Blue (BL)
Red (RD)
Magenta (MAG)
Green (GRN)
I'm thinking of casting but couldn't get it to work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
please try the following:
toString(textOnStringList(toStringList(%{11300}),toString(findPattern(^%,"(?<=\\().+?(?=\\))"))))
Using this regular expression should do the trick for any number of characters between brackets.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is awesome! Sorry for just getting back to you now. The old script I was using was
replaceAll(replaceAll(toString(textOnStringList(toStringList(%{19401}), substring(^%,length(^%)-4,length(^%)-1))), "\\s", ""), "\\x28", "")
Somehow, it worked. But revisited everything and applied yours. It is much much better! Thank you so much!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.