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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,552,598
Community Members
 
Community Events
184
Community Groups

Trying to use 2 custom fields to determine a scripted field value using ScriptRunner Script Fields

Hi,

I have 2 custom fields configured as Select List (single choice) which is completed on a screen during the workflow's 1st transition.  These 2 fields are used to determine the 3rd custom field which is configured as a Scripted Field.

Below is the script however when using the PREVIEW option, it always returns a NULL result even though the Preview Issue Key used has values that are in the def values section.  Configure Context and Screens has been completed.

I have also created a ticket using both scenarios in the def values section however the scripted field is not displaying on the screen configured.

Would greatly appreciate any advice on how to rectify this issue.

 

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

int consequenceId = 17301
int likelihoodId = 17300
int targetFieldId = 17302

def consequence = getFieldById("customfield_" + consequenceId)
def consequenceValue = consequence.getValue()
def likelihood = getFieldById("customfield_" + likelihoodId)
def likelihoodValue = likelihood.getValue()
def targetField = getFieldById("customfield_" + targetFieldId)

def values = [[Consequence:"Severe", Likelihood:"Certain", TargetValue:"High"],
[Consequence:"Minimum", Likelihood:"Rare", TargetValue:"Low"]]

def targetFieldValue = values.find { it.Consequence == consequenceValue &&
it.Likelihood == likelihoodValue}?.TargetValue
if (targetFieldValue != null){
targetField.setFormValue(targetFieldValue)
}

3 answers

2 accepted

0 votes
Answer accepted
This is the behavior script that now works with the targetField a custom text field and the consequence and likelihood fields list single choice fields.
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

int consequenceId = 17301
int likelihoodId = 17300
int targetFieldId = 17309

def consequence = getFieldById("customfield_" + consequenceId)
def consequenceValue = consequence.getValue()
def likelihood = getFieldById("customfield_" + likelihoodId)
def likelihoodValue = likelihood.getValue()
def targetField = getFieldById("customfield_" + targetFieldId)

def values = [[Consequence:"Severe", Likelihood:"Certain", TargetValue:"Reportable"],
[Consequence:"Severe", Likelihood:"Likely", TargetValue:"Reportable"],
[Consequence:"Severe", Likelihood:"Possible", TargetValue:"Reportable"],
[Consequence:"Severe", Likelihood:"Unlikely", TargetValue:"Reportable"],
[Consequence:"Severe", Likelihood:"Rare", TargetValue:"Reportable"],
[Consequence:"Major", Likelihood:"Certain", TargetValue:"Reportable"],
[Consequence:"Major", Likelihood:"Likely", TargetValue:"Reportable"],
[Consequence:"Major", Likelihood:"Possible", TargetValue:"Reportable"],
[Consequence:"Major", Likelihood:"Unlikely", TargetValue:"Reportable"],
[Consequence:"Major", Likelihood:"Rare", TargetValue:"Reportable"],
[Consequence:"Moderate", Likelihood:"Certain", TargetValue:"Investigate"],
[Consequence:"Moderate", Likelihood:"Likely", TargetValue:"Investigate"],
[Consequence:"Moderate", Likelihood:"Possible", TargetValue:"Investigate"],
[Consequence:"Moderate", Likelihood:"Unlikely", TargetValue:"Investigate"],
[Consequence:"Moderate", Likelihood:"Rare", TargetValue:"Review"],
[Consequence:"Minor", Likelihood:"Certain", TargetValue:"Review"],
[Consequence:"Minor", Likelihood:"Likely", TargetValue:"Review"],
[Consequence:"Minor", Likelihood:"Possible", TargetValue:"Review"],
[Consequence:"Minor", Likelihood:"Unlikely", TargetValue:"Track"],
[Consequence:"Minor", Likelihood:"Rare", TargetValue:"Track"],
[Consequence:"Minimum", Likelihood:"Certain", TargetValue:"Track"],
[Consequence:"Minimum", Likelihood:"Likely", TargetValue:"Track"],
[Consequence:"Minimum", Likelihood:"Possible", TargetValue:"Track"],
[Consequence:"Minimum", Likelihood:"Unlikely", TargetValue:"Track"],
[Consequence:"Minimum", Likelihood:"Rare", TargetValue:"Track"]]

def targetFieldValue = values.find

{ it.Consequence == consequenceValue && it.Likelihood == likelihoodValue}
?.TargetValue
if (targetFieldValue != null)
{ targetField.setFormValue(targetFieldValue) }
0 votes
Answer accepted
Sachin Dhamale
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 13, 2023

@Amanda Tippett

 

If you are using scripted field then you can update them in post function. 

 

if you are using the behavior script then you can use normal text field to update.

 

Thanks,

Sachin

Thank you @Sachin Dhamale this assisted me in getting the results I required.

Although it is painfully that with the behavior script the value does not appear until after a transition has happened.  Found it is a known issue that has been around for some time.

0 votes
Marjina Konile
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!
Apr 14, 2023

Instead of using getValue() to retrieve the field values, try using getSelectedValue() to get the selected option value from the select list. For example:

def consequenceValue = consequence.getSelectedValue() def likelihoodValue = likelihood.getSelectedValue()

Also, ensure that the custom field IDs consequenceId, likelihoodId, and targetFieldId are correct and correspond to the correct custom fields.If the script still doesn't work, you may want to try debugging it by adding some log.debug() statements i hope it will works for you because when i was facing this issue in my project hybrid matress.it was solved 

thnK regarda

Thank you for your advice @Marjina Konile , afraid the getSelectedValue() did not help in this case.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events