Sending an email with Powershell and HTML - Variable Confusion

Hello all,

I have a problem that I know is probably my lack of experience with JavaScript and HTML.

I am sending an email using a powershell template, but it’s not sorting correctly:

Step # Step Name Result
1 Windows Service - Stop Succeeded
2 Backup WAR Succeeded
3 Move WAR Java Succeeded
4 Rename to bc.war Succeeded
5 Windows Service - Start Succeeded
6 Send Email - Powershell Running
0 Acquire Packages Succeeded
7 Apply Tentacle Retention Policy Succeeded

…is how they sort in the email.

I have tried using the unless tag and all sorts of equals operators (which I don’t think work in HTML at all…)

Is there a way to sort these steps?

Attached is the working, but incorrectly sorted, Powershell HTML wrapper script.

Thank you,

Brandonpowershell email.ps1 (3.3 KB)

Hi Brandon,

Thanks for getting in touch. The order you are seeing is a side effect of the order in which we add each step’s variables to the collection internally. Are you able to use the workaround described in this post?

1 Like

It will probably work. Do you know how I could get that to work in my code?

I’m having trouble.

Thank you.

So of course a verbatim copy paste of the code from that post gives me a list, but I’d strongly prefer to format it as a table.

Code I tried to use inside of my each step loop:

#{unless step.number}
<td>#{step | HtmlEscape} &mdash; <strong>#{step.Number}</strong></td>
#{/unless}
#{if step.Status.Code}
#{if step.number}
<td>#{step | HtmlEscape} &mdash; <strong>#{step.Number}</strong></td>
#{/if}
#{unless step.number}
<td>#{step | HtmlEscape} &mdash; <strong>#{step.Name}</strong></td>
#{/unless}
#{if step.Status.Code}
#{if step.number}
<td>#{step | HtmlEscape} &mdash; <strong>#{step.Name}</strong></td>
#{/if}
#{unless step.number}
<td>#{step | HtmlEscape} &mdash; <strong>#{step.Status.Code}</strong></td>
#{/unless}
#{if step.Status.Code}
#{if step.number}
<td>#{step | HtmlEscape} &mdash; <strong>#{step.Status.Code}</strong></td>
#{/if}

Any ideas?

Hi,

This should do it:

<table id="t01">
<tr>
<th>Step #</th>
<th>Step Name</th>
<th>Result</th> 
</tr>
			
#{each step in Octopus.Step}
#{unless step.number}
<tr>
<td>#{Step.Number}</td>
<td>#{Step.Name}</td>
<td>#{Step.Status.Code}</td>
</tr>
#{/unless}
#{/each}
			
#{each step in Octopus.Step}
#{if step.number}
<tr>
<td>#{Step.Number}</td>
<td>#{Step.Name}</td>
<td>#{Step.Status.Code}</td>
</tr>
#{/if}
#{/each}		
			
</table>
1 Like

Excellent. Thank you.

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