Workflow: Fetch Array from HTTP request and send in Email in a table with separated values

Hi Team!

I am constructing a workflow to notify when an identity that is owner of an object in IDN is about to be off-boarded.

To do this I use the “Get List of Identities” Action and use it as input to a Loop where I send a /search HTTP request that fetches objects that are owned by these identities. I then use the request body of this HTTP request in a “Send Email” action where I want to print the Object Name and Object Type.

I have made 2 variables:

"accessList.$": "$.hTTPRequest.body[*].name"
"accessType.$": "$.hTTPRequest.body[*].type"

I am able to fetch the data needed, however when there lists are returned, I am unable via velocity code to loop these lists and split the values into separate rows of a table.

Result when there is only 1 object:
image

Result when there are several objects:
image

I have tried to separate items when Arrays are returned, to no success. I’m not sure the Velocity engine in IdentityNow supports the code I have tried.

I have tried different code but here is an example:

<thead>
<tr>
<th>Access Type</th>
<th>Access List</th>
</tr>
</thead>
<tbody>
#if ($accessType && $accessType.getClass().isArray())
  #foreach ($index in [0..$accessType.size() - 1])
    #set ($typeItem = $accessType[$index])
    #set ($item = $accessList[$index])
<tr>
<td>$typeItem</td>
<td>$item</td>
</tr>
  #end
#else
<tr>
<td>$accessType</td>
<td>$accessList</td>
</tr>
#end
</tbody>

This code breaks the email.

Does anyone know how to split the values of the arrays and put these in a table with separated rows?

I have also tried simply replacing square brackets and commas if there are arrays returned like so:

<thead>
<tr>
<th>Access Type</th>
<th>Access List</th>
</tr>
</thead>
<tbody>
#set($typeItems = $accessType.replaceAll("[\\[\\]]", "").split(","))
#set($itemValues = $accessList.replaceAll("[\\[\\]]", "").split(","))
#foreach($index in [0..$typeItems.size() - 1])
  #set($type = $typeItems[$index].trim())
  #set($item = $itemValues[$index].trim())
<tr>
<td>$type</td>
<td>$item</td>
</tr>
#end
</tbody>

Thankful for any help!

Workflow screenshot:

I realised i was checking for an Array but when checking class.name for the variable with multiple values it returns java.util.ArrayList.

I changed it to the following code:

<table style="margin-top:3px;background-color:#ffffff;border:1px solid #bbbbbb;border-collapse:collapse;color:#333333;font-family:'helvetica','arial',sans-serif">
<thead>
<tr>
<th>Access Type</th>
<th>Access List</th>
</tr>
</thead>
<tbody>
  #if ($accessType && $accessList.class.name == "java.util.ArrayList")
    #set ($stop = $accessType.size() - 1)
    #foreach ($index in [0..$stop])
      #set ($typeItem = $accessType.get($index))
   	  #set ($item = $accessList.get($index))
	  #if ($typeItem == "accessprofile")
	    #set ($typeItem = "Accessprofil")
	  #elseif ($typeItem == "role")
	    #set ($typeItem = "Roll")
	  #else
	  #end
	  #set ($typeCell = "<td style='border:1px solid #bbbbbb;padding:5px;background-color:#dddddd;font-weight:bold'>" + $typeItem + "</td>")
	  #set ($listCell = "<td style='border:1px solid #bbbbbb;padding:5px'>" + $item + "</td>")
	  <tr>
	    $typeCell
	    $listCell
	  </tr>
    #end
  #else
    #if ($accessType == "accessprofile")
	  #set ($accessType = "Accessprofil")
	#elseif ($accessType == "role")
	  #set ($accessType = "Roll")
	#else
	#end
	#set ($typeCell = "<td style='border:1px solid #bbbbbb;padding:5px;background-color:#dddddd;font-weight:bold'>" + $accessType + "</td>")
	#set ($listCell = "<td style='border:1px solid #bbbbbb;padding:5px'>" + $accessList + "</td>")
	<tr>
	  $typeCell
	  $listCell
	</tr>
  #end
</tbody>

Don’t mind the different setters for translation :slight_smile:

This works and outputs:

image

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