Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to dynamically change the priority according to two custom fields ?

Nath April 15, 2019

Hi,

In Jira server, I try to set the priorty field according the value of two custom fields : Criticity and Impact. For that, I use behaviours (script runner). Currently, my script set the priority field correctly, but I can't set it when the user selects the values ​​in the custom fields (dynamically).

Here is my code :

def fCriticity = getFieldById( "customfield_10600" )
def fImpact = getFieldById( "customfield_10601" )
def fpriority = getFieldById( "priority" )
def fpriority0 = getFieldById( "priority-field" )

fpriority.setReadOnly( true )

String vCriticity = (String) fCriticity .getValue()
String vImpact = (String) fImpact.getValue()


if ( ( vCriticity == "Block" ) && ( vImpact == "Strong" ) )
{
fpriority.setFormValue( 1 )
fpriority0.setFormValue( "Very high" )
}
if ( ( vCriticity == "Block" ) && ( vImpact == "Medium" ) )
{
fpriority.setFormValue( 2 )
fpriority0.setFormValue( "High" )
}
if ( ( vCriticity == "Block" ) && ( vImpact == "Low" ) )
{
fpriority.setFormValue( 3 )
fpriority0.setFormValue( "Medium" )
}
if ( ( vCriticity == "Major" ) && ( vImpact == "Strong" ) )
{
fpriority.setFormValue( 2 )
fpriority0.setFormValue( "High" )
}
if ( ( vCriticity == "Major" ) && ( vImpact == "Medium" ) )
{
fpriority.setFormValue( 3 )
fpriority0.setFormValue( "Medium" )
}
if ( ( vCriticity == "Major" ) && ( vImpact == "Low" ) )
{
fpriority.setFormValue( 4 )
fpriority0.setFormValue( "Low" )
}
if ( ( vCriticite == "Minor" ) && ( vImpact == "Strong" ) )
{
fpriority.setFormValue( 3 )
fpriority0.setFormValue( "Medium" )
}
if ( ( vCriticity == "Minor" ) && ( vImpact == "Medium" ) )
{
fpriority.setFormValue( 4 )
fpriority0.setFormValue( "Low" )
}
if ( ( vCriticity == "Minor" ) && ( vImpact == "Low" ) )
{
fpriority.setFormValue( 4 )
fpriority0.setFormValue( "Low" )
}

I tried with underlying, but nothing works.
Could you help me please ?
Thank you.

Nath

2 answers

2 accepted

0 votes
Answer accepted
Nath April 19, 2019

Hi,

When I use this behaviour, the value is updated in the transition, but not the image (arrows). And the value stored is not right. What can I do to solve my problem ?

Nath

Antoine Berry
Community Champion
April 19, 2019

Hi,

That's weird, are you sure you do not have any side operation that updates the priority ?

Antoine

Nath April 19, 2019

Hi Antoine,

Yes, I'm sure. Nothing else updates the priority. I don't understand why it's OK when we are in the transition view and why it's KO in the issue view.

Nath

Antoine Berry
Community Champion
April 19, 2019

You could maybe try to add

import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.component.ComponentAccessor

def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
underlyingIssue.store()
issueIndexingService.reIndex(underlyingIssue)

in the script, but this will only work if issue is created already (so underlyingIssue exists).

Nath April 19, 2019

Is there another solution to set the priority field according the value of two custom fields ?

Nath

Antoine Berry
Community Champion
April 19, 2019

You can do it in a listener/postfunction instead of behaviours. This means you probably need to put the priority only on view issue screen.

Like Nath likes this
Nath April 23, 2019

Hi,

Thanks for your advice. I have created a Post-function to store the value.

Nath

Like Antoine Berry likes this
0 votes
Answer accepted
Antoine Berry
Community Champion
April 15, 2019

Hi,

Is this script bound to both Criticality and Impact fields in your behaviours settings ?

Antoine

Nath April 15, 2019

Hi,

No it isn't. This script is currently linked to the "priority" field only.

Nath

Antoine Berry
Community Champion
April 15, 2019

In that case you can debind it from the priority field and bind it to Criticality and Impact fields, that should do the trick. Behaviours will listen to an update on those fields and update priority accordingly.

Antoine

Like Nath likes this
Nath April 15, 2019

That's Great ! The script works !

Thanks a lot Antoine !

Nath

Like Antoine Berry likes this

Suggest an answer

Log in or Sign up to answer