Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Scriptrunner: Access Value from Numeric Field

Brandon Moberg
Contributor
November 22, 2023 edited

Hello!

I'm trying to use ScriptRunner Behaviours to make a field read-only once it's filled out. I can get this to work for certain field types (i.e., single-select) but not for numeric field types. Any ideas how to access the "value" for a numeric field type or is it not possible? TYIA!

Script

var storyPoint = getFieldById("customfield_XXXXX")

var storyPointValue = storyPoint.getValue()

if(storyPointValue != null){

storyPoint.setReadOnly(true);

}

else {

storyPoint.setReadOnly(false);}

Single-Select Field Example 

  •  This works fine because there's a value object to return.
 "customfield_10255": {
    "self": "https://< >.atlassian.net/rest/api/2/customFieldOption/10424",
    "value": "Yes",
    "id": "10424"
  },

Numeric Field Example 

  • How do I return the "value" (i.e., 5) in my script so it'll work?
 "customfield_10025": 5,

 

1 answer

1 vote
Bobby Bailey
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.
November 22, 2023

Hi @Brandon Moberg , 

Unfortunately, Behaviours on Jira Cloud does not currently support the Numeric Custom Field Type. As the underlying API we use for Behaviours is still being developed by Atlassian, there are a number of fields types that Atlassian have not yet built support for, so we cannot include them in our Behaviours feature.

You can find a full list of what fields are supported, and what actions on those fields are supported in our documentation here.

You can also leave us feedback on what features you would like to see next in Behaviours on our Nolt Board here. Whilst we don't decide what Atlassian will work on next, we can take the feedback we get from customers to let them know what you are looking for! 

Sorry I wasn't able to give you a more helpful answer. 

Kind regards, 

Bobby

Kristian Walker _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.
November 23, 2023

Hi Brandon,

As Bobby mentioned, number fields are not yet supported.

The only workaround is to call the .toString() method to return the value as a string and set this in a text custom field.

Regards,

Kristian

Brandon Moberg
Contributor
November 27, 2023

Hi there,

Thank you for the replies, I appreciate it. @Kristian Walker _Adaptavist_ do you have an example of the workaround you mention?

When I add .toSring() method to my value I'm returning an [object object] string. How do I return the appropriate value (i.e., 5)? From there, I track the suggestion to set this value in a separate field and make that field required to mimic the desired functionality. 

Kristian Walker _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.
November 28, 2023 edited

Hi Brandon,

I can confirm the object object error being returned means the value is an Object, and you need to extract the value out of the object to be able to set this as a String.

I have created the example, which you can view here, and this shows how to get the value out of a single Select List field and set it in a text field on the Create Screen using Behaviours in Jira Cloud.

You can use this example as a guide to help achieve your requirements. 

It will not be possible to get a number field value as Bobby mentioned, as you can only set values to a text field which is returned from fields which Behaviours supports.

I hope this answer helps.

Regards,

Kristian

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Upcoming Jira Events