Iterating hash table in Email Notification Step

(Fuat) #1

I have a hash-table which is created and converted to json in one of deployment steps like:

$testHashTable= @{}
$testHashTable.add( "keytest", "valuetest" )
$testHashTable.add( "keytest2", "valuetest2" )
Set-OctopusVariable -name "TestHashTable" -value ($testHashTable| convertto-json)

The problem is: I want to iterate this variable in the email body but i could not find a solution. Could you please show me a way to do it if possible?
I tried something like shown below which is not working:

<table>
  <tr>
    <th>Title_Key</th>
    <th>Title_Value</th>
  </tr>
  #{each key in (Octopus.Action[StepA].Output.TestHashTable | convertfrom-json).keys}
	<tr>
		<td>#{key}</td>
		<td>#{(Octopus.Action[Binary Hash Calculation].Output.TestHashTable | convertfrom-json)[key]}</td>
	</tr>
#{/each}
</table>
(Henrik Andersson) #3

Hi Fuat,

Thanks for getting in touch.

You got it mostly right, but you can’t use PowerShell cmdlets, e.g. convertfrom-json, in the email step as it doesn’t run through PowerShell.

I’ve modified your email template below that should give you the result you’re after.

<table>
  <tr>
    <th>Title_Key</th>
    <th>Title_Value</th>
  </tr>
  #{each item in Octopus.Action[YourStepName].Output.TestHashTable}
	<tr>
		<td>#{item.Key}</td>
		<td>#{item.Value}</td>
	</tr>
#{/each}
</table>

I hope that helps.

Thank you and best regards,
Henrik

(Fuat) #4

This works. Thank you so much

(Henrik Andersson) #5

Hi Fuat,

Great to hear that it worked for you.

Thank you and best regards,
Henrik

(system) closed #6

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