Want to show script output as $0

Manoj Gangwar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 12, 2024

Hi All,

I have a script and currently its showing output value in Number like 0, 12, 123 but I want to show the output like $0, $12, $123.

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.search.SearchProvider

import com.atlassian.jira.web.bean.PagerFilter

import com.atlassian.jira.issue.IssueManager;

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.issue.link.IssueLinkManager

import com.atlassian.jira.user.ApplicationUser

import java.text.NumberFormat

def issueManager = ComponentAccessor.getIssueManager()

def linkManager = ComponentAccessor.getIssueLinkManager()

def cfm = ComponentAccessor.getCustomFieldManager()

Issue issueKey = issue

def id=issueKey.getId()

def customFieldManager = ComponentAccessor.getCustomFieldManager();

def cf1 = customFieldManager.getCustomFieldObject(29041)

def cf2 = customFieldManager.getCustomFieldObject(29042)

def cf3 = customFieldManager.getCustomFieldObject(29043)

def cf4 = customFieldManager.getCustomFieldObject(30304)

def n = Integer.parseInt((issue.getCustomFieldValue(cf1) ?: 0).toString().replaceAll(~/[.].*/, ""))

def b = Integer.parseInt((issue.getCustomFieldValue(cf2) ?: 0).toString().replaceAll(~/[.].*/, ""))

def c = Integer.parseInt((issue.getCustomFieldValue(cf3) ?: 0).toString().replaceAll(~/[.].*/, ""))

def d = Integer.parseInt((issue.getCustomFieldValue(cf4) ?: 0).toString().replaceAll(~/[.].*/, ""))

Integer sum = (n ?: 0) + (b ?: 0) + (c ?: 0) + (d ?: 0);


 

 

3 answers

3 accepted

0 votes
Answer accepted
Manoj Gangwar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 14, 2024

Added the below script and it works as expected.

 

def decimalFormat = new DecimalFormat("###,###")

def formattedSum = "\$" + decimalFormat.format(sum)

return formattedSum

 

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 13, 2024

Hi @Manoj Gangwar

Could you please share a screenshot of your Scripted Field configuration so I can better understand the field type you are using?

If you have set the Scripted Field to Number Field type, then it is not doable because the number field will only take Numbers and Decimal points.

However, if you are using the Text Field, then yes, you can add the $ symbol.

I am looking forward to your feedback.

Thank you and Kind regards,

Ram

Manoj Gangwar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 13, 2024

Hi @Ram Kumar Aravindakshan _Adaptavist_ , 

I have set the scripted field to Text field type. 

0 votes
Answer accepted
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 12, 2024

So add a dollar to it and return it as String?

Suggest an answer

Log in or Sign up to answer