Editing search results preview inside SOD policy email template

Has anyone had any luck making changing how the SOD policy violation email template display the search result preview table? I’m wondering how the velocity code would need to be modified to pick and choose which columns are displayed. Below is the current code.

Results Preview:<table
    style="margin-top:3px;background-color:#ffffff;border:1px solid #bbbbbb;border-collapse:collapse;color:#333333;font-family:&#39;helvetica&#39; , &#39;arial&#39; , sans-serif">

    #set ($isHeader &#61; true) #foreach ($previewRow in ${searchResults.get($documentType).get(&#34;preview&#34;)})
    <tr> #foreach ($previewCell in ${previewRow}) #if ($isHeader) <th
            style="border:1px solid #bbbbbb;padding:5px;background-color:#dddddd;font-weight:bold">${previewCell}</th>
        #else <td style="border:1px solid #bbbbbb;padding:5px">${previewCell}</td> #end #end </tr> #set ($isHeader &#61;
    false) #end
</table>
</p> #end#else <p> ${policyName} is returning no results at this time. </p>#end

I am hoping to only return the identity username, displayname, and manager displayname.

Screenshot to show how difficult the table is to read.

Try this…

<table style="margin-top:3px;background-color:#ffffff;border:1px solid #bbbbbb;border-collapse:collapse;color:#333333;font-family:&#39;helvetica&#39; , &#39;arial&#39; , sans-serif">
    #set ($isHeader &#61; true)
    #set ($selectedColumns = ["identity username", "displayname", "manager displayname"])
    #set ($filteredColumns = [])
    #foreach ($previewRow in ${searchResults.get($documentType).get(&#34;preview&#34;)})
        <tr>
            #set ($filteredColumnIndex = 0)
            #foreach ($previewCell in ${previewRow})
                #set ($filteredColumnIndex = $filteredColumnIndex + 1)
                #if ($isHeader)
                    #if($selectedColumns.contains($previewCell))#set($dummy = $filteredColumns.add($filteredColumnIndex))#end
                    #if($selectedColumns.contains($previewCell))<th style="border:1px solid #bbbbbb;padding:5px;background-color:#dddddd;font-weight:bold">${previewCell}</th>#end
                #else
                    #if($filteredColumns.contains($filteredColumnIndex))<td style="border:1px solid #bbbbbb;padding:5px">${previewCell}</td>#end
                #end
            #end
        </tr>
        #set ($isHeader &#61; false)
    #end
</table>

Use appropriate values in place of "identity username", "displayname", "manager displayname" that will match the displayed values in the header row

3 Likes

That pretty much solved it!

I can’t figure out why the true is displaying though. The if statement is doing it’s job by bolding the first row.

image

I think it is the second if condition…

Try replacing this line

#if($selectedColumns.contains($previewCell))$filteredColumns.add($filteredColumnIndex)#end

with this:

#if($selectedColumns.contains($previewCell))#set($filteredColumns.add($filteredColumnIndex))#end

And don’t forget to mark as Solution :smiley:

Hmm, it doesn’t like the syntax in that set. The error is in between the two parens.

I am not an expert in Velocity Templates. So not entirely sure what is the issue… But I think
In the original line

#if($selectedColumns.contains($previewCell))$filteredColumns.add($filteredColumnIndex)#end

$filteredColumns.add($filteredColumnIndex) was returning a string true that was shown in the table header cells.

I thought

#if($selectedColumns.contains($previewCell))#set($filteredColumns.add($filteredColumnIndex))#end

would resolve the issue, but apparently it does not. So, I think if we assign that string true to a dummy variable then it will not display in the output

Can you try this line instead and see if it works?

#if($selectedColumns.contains($previewCell))#set($dummy = $filteredColumns.add($filteredColumnIndex))#end

Also, it seems like you have an extra #end after the line that is returning the error

That did the trick! Could you edit the solution or do I need to unmark it first?

1 Like

Awesome!! I edited the original solution to reflect this!!

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