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

Use Asset fields in script

Anna Smirnova
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 3, 2023

Hello!
I have requirement, if the field have specific value, I have to show or hide other fields on JSM portal. And it works perfectly with usual fields and easy behaviour:

def projectCategory = getFieldByName("Category")
def otherProjectCategory = getFieldByName("Category Name")

def selectedOption = projectCategory.getValue() as String
log.debug "Selected option: $selectedOption"

if (selectedOption == "Other" ) {
otherProjectCategory.setHidden(false)
otherProjectCategory.setRequired(true)

}
else {
otherProjectCategory.setHidden(true)
otherProjectCategory.setRequired(false)
}

But now instead of usual custom field “Category” I need to use Asset field “Category”. But then script is not working.

Is there any way to do it?

1 answer

Suggest an answer

Log in or Sign up to answer
1 vote
Peter-Dave Sheehan
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.
May 3, 2023

The behavior getValue() method on Insight Custom fields, will return the Object's Key (as String), not the label or name of the object.

Also, it might return a single string or an array of strings depending on a few factors.

  • Whether you are in a regular jira screen or portal screen
  • Whether the field allows a single value or multiple

In the portal,  single fields will always return a single string value and multiple fields will always return an array - even an empty field will return an empty array.

In Jira, single fields always return a single string value. Multiple fields will return a string value if the field is empty or contain a single value and they'll return an array when you have more than one value selected.

You can place a simple script on that field to see for yourself what condition returns what

def formField = getFieldById(fieldChanged)
def val = formField.value
formField.setHelpText("$val ${val.getClass()}")

So in terms of your script logic, you either need to lookup the object key that matches "Other" and put that key in your script.

Or deal with the complex insight java api to load the object that match the selected key and read some attribute to base your logic on.

Tasneem Bhyat July 26, 2024

hi there

 

The above behaviour script works fine in Firefox but in Chrome (127.x update) (using portal), the value received is blank, and yet on Firefox portal the value is retrieved correctly.

 

Has anyone experienced this issue please. It was working fine before the Chrome update to 127 ran..

 

 

TAGS
AUG Leaders

Atlassian Community Events