Is there a way to assign multiple KM variables from one js script?

I can call KM variables from within the script but I’m having trouble writing to them. I can get it so that the last returned variable of the script is then assigned to a variable, which is built in to the Execute Script action. But I’m wondering if you can write to KM variable directly from within a js script. Thanks

You can get multiple results out of a script in a variety of ways.

You can combine them together in some format that you can later split them apart in. For example, you could use a comma separated list, or if comma may appear in your text, perhaps linefeed separated, or bullet separated, or even some sort of magic string like “,KMBREAK,”. Then you simply use the Search Variable action to split them back apart.

Alternatively, you can use AppleScript to write variables directly as described in the Scripting section of the documentation.

Thanks for suggesting this. I gave it a shot but I was having trouble coming up with the correct regular expression. In your example if I had a string variable with that was:

“string1KMBREAKanotherstring2KMBREAKyetonemorestring3KMBREAK”

how would I break this into separate variables using Search Variable? Thanks

Hey John,

Something like this.

-Chris


RegEx to Split String into Variables.kmmacros.zip (874 Bytes)

2 Likes

Thank you very much for providing this!