Need Scripted Custom Filed for particular workflow statuses

Amit Kumar Singh
Contributor
March 1, 2022

Need Scripted Custom Filed for particular workflow statuses, example are in attached image. like for initial 3 status, that field should show Stage - 0, then next two status that field should show 1 the 2,3,4 & 5.

 

Scripted Custom Filed for particular workflow statuses.PNG

1 answer

0 votes
Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 1, 2022

I'd probably do something like lozenges https://aui.atlassian.com/aui/7.9/docs/lozenges.html if you don't require to filter on the values. If you do need to filter on it then a text-field template would probably be easier for use.

Template: Custom

(== Velocity markup)

Custom Template:

#if ($value == "Stage 0")
##Blue
<span class="aui-lozenge aui-lozenge-current">$value</span>
#elseif ($value == "Stage 1")
##Yellow-ish
<span class="aui-lozenge aui-lozenge-moved">$value</span>
#end

Script:

Map<String, String> statusToStageMap = new HashMap<>()
statusToStageMap.put("Open", "Stage 0")
statusToStageMap.put("Backlog", "Stage 0")
statusToStageMap.put("In Progress", "Stage 0")
statusToStageMap.put("Done", "Stage 1")

String statusName = issue.getStatus().getName()


return statusToStageMap.get(statusName)

//Edit - removed try/catch since hashmap will return null in case it doesn't have our status
//If the status is not mapped, it will return null - meaning nothing is shown on issue
//If it is mapped, we return the relevant "Stage X", which is passed over to Velocity template as $value

 

And as a result you get something like this:

2022-03-01 17_25_11-Fields.png

 

Obviously there's a lot you can customize, you don't have to use velocity, or you can use your own color scheme, there might be a better way to do status mapping with better performing filtering (since this would have to get defined and filtered each single time an issue is "activated"), but it's sort of the first idea that comes to mind.

 

 

Amit Kumar Singh
Contributor
March 2, 2022

Hi @Radek Dostál , Thank you so much! below code is working fine for me...

Map<String, String> statusToStageMap = new HashMap<>()

statusToStageMap.put("Lead Generation", "Stage 0")
statusToStageMap.put("Lead Intake", "Stage 0")
statusToStageMap.put("Assessment", "Stage 0")
statusToStageMap.put("Solution Approach", "Stage 0")
statusToStageMap.put("Opportunity Queued for Delivery Team", "Stage 1")
statusToStageMap.put("Requirements and Design", "Stage 1")
statusToStageMap.put("Build/Engineer", "Stage 2")
statusToStageMap.put("User Acceptance Testing", "Stage 2")
statusToStageMap.put("Deploy/Implement/Warranty", "Stage 3")
statusToStageMap.put("Production", "Stage 3")
statusToStageMap.put("Production Value Validated", "Stage 4")
statusToStageMap.put("Retired", "Stage 4")
statusToStageMap.put("Declined", "Stage 5")

String statusName = issue.getStatus().getName()


return statusToStageMap.get(statusName)

Amit Kumar Singh
Contributor
March 2, 2022

@Radek Dostál  need one more help as below code is not working for me, also need Five color name for all 5 stages... for above code.... ---

if ($value == "Stage 0")
Blue
<span class="aui-lozenge aui-lozenge-current">$value</span>
elseif ($value == "Stage 1")
Yellow-ish
<span class="aui-lozenge aui-lozenge-moved">$value</span>
end

Error - 

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script46.groovy: 3: unexpected token: < @ line 3, column 1.
Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 2, 2022

Did you paste it including # and ##?

# is a velocity markup indicating a tag

## is a comment

 

And is the template for sure Custom like this?

asdasd.png

(disregard the text, it's from another field)

Amit Kumar Singh
Contributor
March 2, 2022

When i paste including # and ##?, it shows below error.

The script could not be compiled:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script50.groovy: 1: expecting '!', found 'i' @ line 1, column 2.
   #if ($value == "Stage 0")

Suggest an answer

Log in or Sign up to answer