Formatting an Array into a String inside a Workflow

Hello All!

I’m trying to see if it’s possible to format an Array in the format below into the string output below. I have an array coming from a trigger in my workflow that needs to be formatted into a comma separated list without knowing the total size of the array. I was thinking about hard coding it all in a DefineVariable, but that doesn’t work when introducing different array sizes. Is there an easy way to do this with a loop that I’m not getting?

[“TestString1”, “TestString2”, “TestString3” ]

String output:
TestString1, TestString2, TestString3

Hi @trettkowski ,

Not sure if it works as i have not tested this, but based on my understanding, Try using Java docs | SailPoint Developer Community " * * connector.common.Util**" listToCsv(java.util.List list) which returns string from a list.

you can use this to write a custom rule and then create a custom transform of type rule like below:

{
  "type": "rule",
  "name": "Join Array to String Transform",
  "input": {
    "type": "reference",
    "transform": "MyArrayAttribute" // Reference to the array attribute
  },
  "delimiter": ", " // The character(s) to use between array elements
}

refer create-transform | SailPoint Developer Community to create custom transform.

Hello @trettkowski ,

I can suggest you something a little tricky :grinning_face:

Inside a workflow, you can use a Define Variable, create a new variable, and then add this :

You can replace the Text operation by you desired input.

Here is the JSON Advanced Code because the UI is bugged when you try to put a empty patern :

{“name”: “fromArraytoString”,“description”: “”,“transforms”: [{“id”: “sp:transform:replace:string”,“input”: {“pattern”: “\\\"”,“replacement”: “”}},{“id”: “sp:transform:replace:string”,“input”: {“pattern”: “\\[”,“replacement”: “”}},{“id”: “sp:transform:replace:string”,“input”: {“pattern”: “\\]”,“replacement”: “”}}],“variableA”: “["test1","test2","test3"]”}

I hope my post will help you :grinning_face:

1 Like

I’ve attempted to solve this a few times in my workflows, but come up with pretty much the same struggle as you. We have in input of multiple user Ids, and pushing that into an Identity Search.

The best that were were able to come up with using the static entries. Ideally, you add in too many array entries, and use the replace to get rid of the invalid ones. In our case, we break it out into two separate define variables. One to extract the values from the array, and a second to format it. To get around the NULL issue add them as text using the {{$.array[0]}} format. Then in your second define variable, you can use a regex pattern to get rid of extra commas and variables that failed to compute. It is a little overly complicated, but it works if you know the upper side limit of how many elements are in your array.

Where are you looking to output this information?

Thanks @LEOS & @jrote01 for the responses!

@jrote01 , I’m trying to take this string output and use it as input for another form or an email. Basically it’s being used to display the information in the array for approval purposes. My upper bound is 30, so hard coding the array values I don’t think will work in my case. But theoretically, I could just use 1 definevariable operation with 30 variables and take the outputs of that into a second define variable that concat’s each of the 30 variables?

@LEOS , I attempted this, but it appears to display no text when testing the output in a form or email. Keep in mind, my variableA input is an Array of Strings. Does this only work for string inputs?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.