Conditional Formatting
Conditional formatting can be achieved by using multiple merge fields, each matching a condition’s appropriate result. The default test run template contains a good example:
The item.testCaseRuns.result.name is formatted and colored differently depending on its value. To make this work, you must introduce new merge fields by creating velocity macros. During rendering, only one of the merge fields will have value; the others will be rendered empty.
See example merge fields below:
#macro(field_item_testcaseruns_result_namepassed)

#set($result = $leaf.get("name").getAsString())

#if($result == "Passed")

$result.toUpperCase()

#end

#end



#macro(field_item_testcaseruns_result_namefailed)

#set($result = $leaf.get("name").getAsString())

#if($result == "Failed")

$result.toUpperCase()

#end

#end



#macro(field_item_testcaseruns_result_nameelse)

#set($result = $leaf.get("name").getAsString())

#if($result != "Passed" && $result != "Failed")

$result.toUpperCase()

#end

#end



#macro(field_item_testcaseruns_notrunyet)

#set($result = $leaf.get("result"))

## if result is null

#if("$!result" == "")

NOT RUN YET

#end

#end
By default, empty fields receive a -- value. If -- appears for all merge fields, it can be a problem. This can be avoided by adding new entries to existing macros callednot_available. This provides the value which is shown for empty fields.
## empty fields are populated with some n/a value to clearly show something is not available

## if a merge field result remains empty during merging then this macro is run to populate some value



#macro(not_available)



## Some specific merge fields don't need n/a value but should be actually empty.



## - A notification is present or not, it is never missing.

## - Chapter number is also not missing, but it is present or not.

## - Conditional fields also use this behaviour.

## From multiple fields only one will get value, others remain empty.



#if( $fieldName != "item_changenotif"

&& $fieldName != "item_chapter"

&& $fieldName != "item_testcaseruns_result_namepassed"

&& $fieldName != "item_testcaseruns_result_namefailed"

&& $fieldName != "item_testcaseruns_result_nameelse"

&& $fieldName != "item_testcaseruns_notrunyet"

&& $fieldName != "item_assocout_to_urlkeyid"

&& $fieldName != "item_assocout_urlurl")

$!naValueFromTemplateParameters

#end
Was this helpful?