I need to calculate new field value based on other field value in current issue. We need to write a custom script to achieve it.
For example, we have following fields Estimate ( 1-5) ,Competitive (1-5), Customer Impact (1-3), Market Need (1-5) and Priority (1-4)
When estimate is a , Competitive b, Customer Impact c, Market need d , priority e, then new field value is x.
Please can someone help me with the custom script configuration.
Thank you in advance!
Hi,
You could get the result you are looking for with calculated attributes in the app Elements Checklist.
In the example picture below, Status, Impact, and Probability are all select lists, but the list values could be numbers, letters, or anything else you need. The Risk column is a calculated attribute.
In order to calculate the risk based on the choices made in the previous three columns, the app allows you to use logical expressions.
This solution doesn't require any scripting, but it is a paid app and the Checklist would replace the custom fields you currently use.
Hope that helps!
Hello Laura,
I installed the trial version plugin. But when I try to configure Structure, it is not accepting custom field value of type other than numbers. Please can you let me know what am I missing.
Thanks in advance!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, it looks like the syntax is not correct for the Estimate attribute. You'll need to put the name of the attribute in brackets and quotation marks like in the example I posted.
You can check out all the details about how advanced calculated fields can be configured here:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Sneha Gopinath ,
Are you trying to automate this on a particular screen (i.e. dynamically change the value of the new field), or in a transition ?
Also, are those fields select lists?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Antoine,
Yes, those fields are of type select list dropdown.
Yes, trying to automate this on create screen.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is possible with scriptrunner. Do you have this app ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please add a behaviour on each of the fields but the target field. Use this script :
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY
@BaseScript FieldBehaviours fieldBehaviours
int estimateId = 12501
int competitiveId = 12502
int customerImpactId = 12503
int marketNeedId = 12504
int targetFieldId = 12505
def estimate = getFieldById("customfield_" + estimateId)
def estimateValue = estimate.getValue()
def competitive = getFieldById("customfield_" + competitiveId)
def competitiveValue = competitiveId.getValue()
def customerImpact = getFieldById("customfield_" + customerImpactId)
def customerImpactValue = customerImpact.getValue()
def marketNeed = getFieldById("customfield_" + marketNeedId)
def marketNeedValue = marketNeed.getValue()
def priority = getFieldById(PRIORITY)
def priorityValue = priority.getValue().getName()
def targetField = getFieldById("customfield_" + targetFieldId)
def values = [[Estimate:"1", Competitive:"1", CustomerImpact:"1", MarketNeed:"1", priority: "Low", TargetValue: "1"],
[Estimate:"2", Competitive:"1", CustomerImpact:"1", MarketNeed:"1", priority: "Low", TargetValue: "2"],
[Estimate:"1", Competitive:"4", CustomerImpact:"1", MarketNeed:"1", priority: "Low", TargetValue: "5"]]
def targetFieldValue = values.find { it.Estimate == estimateValue && it.Competitive == competitiveValue && it.CustomerImpact == customerImpactValue && it.MarketNeed == marketNeedValue && it.priority == priorityValue}?.TargetValue
if (targetFieldValue != null){
targetField.setFormValue(targetFieldValue)
}
You need to adapt it with your field ids and your own data mapping (in the "values" grid). This will work if the fields are simple select list, you are using the native priority field and the target field is a text field. Let me know if you need some tweaking regarding the custom field types.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Antoine,
I have created all five custom fields as select list(single choice). For testing I added only 3 fields, please find the below script. I have added fields for screen.
import groovy.transform.BaseScript
//@BaseScript FieldBehaviours fieldBehaviours (throws an error "Unable to Resolve Class")
import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY
int estimateId = 12501
int competitiveId = 12502
int targetFieldId = 12505
def estimate = getFieldById("customfield_" + estimateId)
def estimateValue = estimate.getValue()
def competitive = getFieldById("customfield_" + competitiveId)
def competitiveValue = competitive.getValue()
def targetField = getFieldById("customfield_" + targetFieldId)
def values = [[Estimate:"1", Competitive:"1", TargetValue: "1"],
[Estimate:"2", Competitive:"2", TargetValue: "2"],
[Estimate:"3", Competitive:"1", TargetValue: "3"],
[Estimate:"2", Competitive:"2", TargetValue: "2"],
[Estimate:"3", Competitive:"3", TargetValue: "3"]]
def targetFieldValue = values.find { it.Estimate == estimateValue && it.Competitive == competitiveValue }?.TargetValue
if (targetFieldValue != null){
targetField.setFormValue(targetFieldValue)
}
But this is not working. Am I missing something?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, have you updated the custom field ids ?
You can add
import com.onresolve.jira.groovy.user.FieldBehaviours
so it does not throw an error. You might check the logs also to look for some error message. Next step would be to display the variable values in the script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.