Calculation custom field based on other custom field during Create of issue

Sandra Meessen August 9, 2018

Hello, I have 4 custom fields: "customer priority", "Impact", "Urgency" and "calculated priority".

When customer priority is empty, Impact = "high" and Urgency 'High" then calculated priority = 1.

I need to calculate this at Create Issue, so user fills in value for Impact and Urgency and leaves Customer Priority empty and Jira calculated the Calculated Priority.

I understand I can't do this in a Post function, because the values are not stored in database yet, from this article (https://community.atlassian.com/t5/Jira-questions/Making-a-JIRA-field-required-based-on-a-value-chosen-on-the/qaq-p/247284) I understand I have to user Validator to retrieve chosen value of Customer Priority, Urgency and Impact to calculate my Calculated Priority. But which Validator do I use and how? Validator at Create Issue.JPG

2 answers

1 vote
Francesc_Arbó
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.
August 9, 2018

Hi @Sandra Meessen,

You can make it using Automation Lite for Jira just creating one condition for each case. In addition, this app is free and Atlassian Verified.

Sandra Meessen August 9, 2018

And without extra add-ons?

Like Oumayma likes this
Francesc_Arbó
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.
August 9, 2018

Without extra apps I did it once with Jira Service Desk Automation but... it's still the same solution.

I have no idea how to do it without any extra app. 

Fazila Ashraf
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 9, 2018

@Sandra Meessen , From screenshot, i think you already have the ScriptRunner plugin. Have you checked using the behaviours?

Sandra Meessen August 9, 2018

Yes, I have Scriptrunner and Behaviours, but I don't know how to set the Behaviours for my requirement. Do I add the fields Customer Priority, Urgency, Impact or do I add the field Calculated Priority? 

Sandra Meessen August 9, 2018

Hello Fazila, I'm trying to setup the Behaviour and come to this point. My code looks logically ok and gives a green bullet for syntax, but which field do I choose (red circle). The one I want to calculate? Or the one(s) I use to calculate? I mapped the Behaviour to my project, issuetypes and workflow. Thank you for your help. Behaviour.JPG

Sandra Meessen August 13, 2018

Hell @Fazila Ashraf, As I understand from the documentation (https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html) the field defined should be the field I use to calculate the other field, but in my situation I use three custom fields to calculate 1 other custom field. So which field do I define in the Behaviour? The custom field I want to calculate is of type "select list (single choice)"

Sandra Meessen August 13, 2018

ello @Fazila Ashraf, In the meantime I found out that I should use the value to set my custom field, but the ID (https://community.atlassian.com/t5/Marketplace-Apps-questions/Behavior-Plugin-Setting-value-of-a-Select-custom-field-based-on/qaq-p/80357) , but it still doesn't work.  Based on the advice in this article I end up with this code in the "initialiser function": 

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor

// Get a pointer to my select list fields
def klantprioSelectList = getFieldByName("Klantprioriteit")
def berekendepriorequestTypeSelectList = getFieldByName("Berekende prioriteit")

// Get the Value of the Klantprioriteit Field
def klantprioVal = klantprioSelectList.getValue()

// If the XX option is selected then set the "Berekende prioriteit" to Option yy
if(klantprioVal == "1"){
// Set the value of the field using the option ID for the yy value
berekendepriorequestTypeSelectList.setFormValue(10070)
}

 What's wrong in the code and is the "initialiser function" the correct place to put it?

Fazila Ashraf
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 13, 2018

Hi @Sandra Meessen

 

I am so sorry that i dint see your followups and totally missed that you have multiple fields by which the value depends on..

Instead of behaviours, using the scripted fields (from the same script runner plugin) will help this. -> https://scriptrunner.adaptavist.com/latest/jira/scripted-fields.html

A sample is as below:

image.png

Let me know if you need any further help

0 votes
Fazila Ashraf
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 9, 2018

Hi @Sandra Meessen

Validators are used to validate the inputs and decide whether to allow the transition or not.

For your scenario, i would use the Scriptrunner's  (commercial plugin) behaviour - https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html 

Suggest an answer

Log in or Sign up to answer