Forums

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

Update two fields(P & W) in Issue create & Issue update event based on fields(I & U)

Sysad
Contributor
December 11, 2019

We have a requirement, as one of our internal team has moved from a "different system" to Jira ServiceDesk. In their different system, They have the following fields

1. Impact- a dropdown custom field with options I1 I2 I3 I4

2. Urgency - a dropdown custom field with options U1 U2 U3 U4

3. Priority - a dropdown system field with options P1 P2 P3 P4

4. Weight - Single-line textbox which holds a number(n1 n2 n3 n4 n5...n10)

I could do the following:

While creating issue user will choose impact and urgency, based on I1 and U2 I can update Priority(P3) and Weight(n3)  using Jira service desk automation 

I couldn't achieve:

I would like to develop the same functionality when Impact & Urgency is edited priority & weight should get updated as well after creating an issue.

Any help is very much appreciated. I tried something similar with a text box but now with options.

Impact:

Extensive/Widespread - I1

Significant/Large- I2

Moderate/Limited- I3

Minor/Localized -I4

Urgency:

Critical - U1

High- U2

Medium -U3

Low- U4

------------------------------------------------------------------------------

Priority:

Critical - P1

High -P2

Medium-P3

Low - P4

Weight:

Single line text box

 

Combinations: I(x) U(y) then P(a) W(n)

 

I1 U1 ---> P1 29

I1 U2 ---> P1 24

I1 U3 ---> P2 19

I1 U4 ---> P4 9

 

I2 U1 ---> P1 25

I2 U2 ---> P2 20

I2 U3 ---> P3 15

I2 U4 ---> P4 5

 

I3 U1 ---> P2 23

I3 U2 ---> P2 18

I3 U3 ---> P3 13

I3 U4 ---> P4 3

 

I4 U1 ---> P2 20

I4 U2 ---> P3 15

I4 U3 ---> P3 10

I4 U4 ---> P4 0

Thanks, in advance

2 answers

0 votes
Antoine Berry
Community Champion
December 17, 2019

Hi @Sysad ,

I would advise to create a behaviours against impact and urgency field, using this script for both of them :

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY

@BaseScript FieldBehaviours fieldBehaviours

log.error("Start of the script...")

def priorityMap = [[impact:"Extensive/Widespread - I1", urgency:"Critical - U1", priority: "1", weight: "29"],
[impact:"Extensive/Widespread - I1", urgency:"High - U2", priority: "1", weight: "24"],
[impact:"Extensive/Widespread - I1", urgency:"Medium - U3", priority: "2", weight: "19"],
[impact:"Extensive/Widespread - I1", urgency:"Low - U4", priority: "4", weight: "9"],
[impact:"Significant/Large - I2", urgency:"Critical - U1", priority: "1", weight: "25"],
[impact:"Significant/Large - I2", urgency:"High - U2", priority: "2", weight: "20"],
[impact:"Significant/Large - I2", urgency:"Medium - U3", priority: "3", weight: "15"],
[impact:"Significant/Large - I2", urgency:"Low - U4", priority: "4", weight: "5"],
[impact:"Moderate/Limited - I3", urgency:"Critical - U1", priority: "2", weight: "23"],
[impact:"Moderate/Limited - I3", urgency:"High - U2", priority: "2", weight: "18"],
[impact:"Moderate/Limited - I3", urgency:"Medium - U3", priority: "3", weight: "13"],
[impact:"Moderate/Limited - I3", urgency:"Low - U4", priority: "4", weight: "3"],
[impact:"Minor/Localized - I4", urgency:"Critical - U1", priority: "2", weight: "20"],
[impact:"Minor/Localized - I4", urgency:"High - U2", priority: "3", weight: "15"],
[impact:"Minor/Localized - I4", urgency:"Medium - U3", priority: "3", weight: "10"],
[impact:"Minor/Localized - I4", urgency:"Low - U4", priority: "4", weight: "0"],]


def priority = getFieldById(PRIORITY)

int impactId = 12100
def impact = getFieldById("customfield_" + impactId)
def impactValue = impact.getValue() as String
log.error("impactValue : " + impactValue)

int urgencyId = 12101
def urgency = getFieldById("customfield_" + urgencyId)
def urgencyValue = urgency.getValue() as String
log.error("urgencyValue : " + urgencyValue)

int weightId = 12102
def weight = getFieldById("customfield_" + weightId)

def priorityValue = priorityMap.find { it.impact == impactValue && it.urgency == urgencyValue }?.priority as String
def weightValue = priorityMap.find { it.impact == impactValue && it.urgency == urgencyValue }?.weight as String
log.error("priorityValue : " + priorityValue)
log.error("weightValue : " + weightValue)

if (priorityValue) {
priority.setFormValue(priorityValue)
}
if (weightValue) {
weight.setFormValue(weightValue)
}

log.error("End of the script...")

 Please make sure the values in the map match exactly your custom field values, except for priority which you can leave as is since it is a system field. Also update the custom field ids. You could set priority and weight fields as read only if needed.

Let me know if that helped.

Antoine

Sysad
Contributor
December 17, 2019

Thank you for your time & effort. Users like you will make the community thrive.

 

  • I have added the script in the server-side script and updated field id's.
  • Used single behavior and added two fields and script to both fields. 
  • Mapped to the project and to all issue types
  • The difference I noticed is that, to an existing issue, inline edit on impact and urgency is not happening instead, the entire edit form is being displayed.
  • When a new issue is created priority is being updated, but weight isn't
  • When updating the existing issue, either priority nor weight is updating.

Based on my implementation, plz correct me if I made a mistake.

As well as I have used two behaviors for two fields and yet the same result.

Antoine Berry
Community Champion
December 17, 2019

Thanks @Sysad :) I will try to help you further to deserve these kind words.

It seems you have done everything right. To ensure that you could screenshot your behaviours configuration. Next step is to add some logs in the script/check the logs. Please see updated answer.

0 votes
Stephen Crandell
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.
December 11, 2019

Does your instance have Script Runner add-on? You could script behaviors for this.

 

https://scriptrunner.adaptavist.com/5.6.7/jira/behaviours-overview.html

Sysad
Contributor
December 11, 2019

Hi

We do have an add-on. Trying to understand which field to be added in mapping.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events