It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can I create a percent field?

I'm thinking a need a number type field that displays as a percentage. Maybe a text field that converts to a number elsewhere may be necessary. I'm not sure what the best route to go would be.

Example:

1. User creates an issue and has to enter a value in a field named Confidence. 

2. The end-user should not have to enter the percent symbol '%' or a decimal '.', just an integer in the range of 0-100.

3. Once the issue has been created, the value should display as a percent.

4. The value in the Confidence will be used in a score calculation.

Any ideas? Any add-ons? Thoughts?

4 answers

2 accepted

1 vote
Answer accepted

Hi @Rhett - I am not completely certain I got your question right. So, what you are trying to do is to have a custom field that can take a number between 0 and 100. And after issue create form (or issue edit form) is submitted, this number (no calculation intended) just shows a percent (%) symbol suffixed to it ?

If my understanding is correct, we are not really getting into the scenario of calculated or scripted fields in any scope. If the '%' symbol is just for a way to show the users the value of the field showing is a percentage, have you considered adding this to the field name itself ? Something to say - "Confidence (%)" ? 

Also, here are a couple of pointers that may help, if you haven't already looked at them -

https://confluence.atlassian.com/adminjiraserver073/configuring-a-custom-field-861253383.html?_ga=2.24759226.1081069868.1576087010-1247131324.1573692024#ConfiguringaCustomField-Options

https://community.atlassian.com/t5/Jira-questions/Custom-field-with-number-form-1-to-100/qaq-p/290684

Sorry, if I completely got your question wrong!

You completely understood and thank you for your reply. I thought about adding the (%) to the field name but hoped someone had a method to change the display itself.

Hey @Kalyani Vunnava [Wittified Atlassian apps] ,

I also have the same question.

But from the above '2' links i got nothing.

Please can you specify some more how to add "%" in my custom field?

 

Hello @Rhett ,

Have you fixed the same? Did you get that '%' on your field?

Please suggest me too.

Thanks!

Regards,

Akbar Pasha.

1 vote
Answer accepted
Elifcan Cakmak Community Leader Dec 12, 2019

Hello,

Here is what you can do, but you need two add-ons for this: Jira Suite Utilities and Script Runner. 

First with JSU plugin, you can add a regular expression validator on your create transition to make sure user enter a number between 0-199.

Second, you can create a scripted field with Script Runner plugin and add % to the number entered by the user with a short groovy script. Then show it to the user on the view screen of the project.

Hope this helps.

Regards,

Elifcan

This is the preferred method and we have ScriptRunner. However, I'm extremely new to using it. I couldn't find anything on their site about how to do this. Any other resources out there that might help in learning?

Elifcan Cakmak Community Leader Dec 16, 2019

Hi,

This is the official documentation for script field:

https://scriptrunner.adaptavist.com/5.0.4/jira/scripted-fields.html

A custom script like below would do:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.event.type.EventDispatchOption

def issueManager = ComponentAccessor.getIssueManager()
def authenticationContext = ComponentAccessor.getJiraAuthenticationContext()
def user = authenticationContext.getLoggedInUser()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customfield = customFieldManager.getCustomFieldObjectByName("number1")

issue.getCustomFieldValue(customfield);
def percentage = "%"+issue.getCustomFieldValue(customfield).toString()
return percentage

To limit the number between 0-100, you need to use Jira Suite Utilities Regular Expression Validator. You need to add it to your workflow transition as validator:

Selection_412.pngHope this helps,

Elifcan

Hi Rhett,

I just wanted to quickly jump in and confirm that you will need an app for that. If you were using Jira Workflow Toolbox (JWT) you could accomplish both requirements with a single app though:-) https://marketplace.atlassian.com/apps/29496/jira-workflow-toolbox?hosting=datacenter&tab=overview

Use cases for calculating a field can be found here:

https://apps.decadis.net/display/JWT/Calculated+Number+Field

The display format can be set independently:

display.png

Regarding the validation of the input field you could use a boolean validator to ensure the number range is being enforced:

https://apps.decadis.net/display/JWT/Boolean+condition+and+validator+with+math.+date-time+or+text-string+terms

Cheers,

Christian

In my jira Instance, i just created a dop down list

0%

1%

.

.

.

99%

100%

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you