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

I want to Hide fields on Resolved Transition screen using behavior but its not working.

Manoj Gangwar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 22, 2023

I have the below script and want to hide the few fields based on the Issue Summary for Sub-task while transitioning it to Resolved. Could you please check and let me know what Am I missing?

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

def summ = getFieldById('summary').value as String
def accountChange = getFieldById('customfield_30200') //Will ISC account change?
def iscAccount = getFieldById('customfield_13423') // ISC Account
def adGroup = getFieldById('customfield_30211') // Add to AD Group
def accountAssigned = getFieldById('customfield_30214') // ALT-Account Assigned
def accountDeleted = getFieldById('customfield_30215') // ALT-Account Deleted
def nameChange = getFieldById('customfield_30216') // New ALT-A Account Assigned due to Name Change
def uAssigned = getFieldById('customfield_33347') // U# Assigned

accountChange.setHidden(true)
iscAccount.setHidden(true)
adGroup.setHidden(true)
accountAssigned.setHidden(true)
accountDeleted.setHidden(true)
nameChange.setHidden(true)
uAssigned.setHidden(true)

if(summ == 'Create "ALT-" account for'){
accountAssigned.setHidden(false)
accountAssigned.setRequired(true)
accountDeleted.setHidden(false)
accountDeleted.setRequired(true)
nameChange.setHidden(false)
nameChange.setRequired(true)
}
else if(summ == 'Delete ALT- account'){
accountAssigned.setHidden(false)
accountAssigned.setRequired(true)
accountDeleted.setHidden(false)
accountDeleted.setRequired(true)
nameChange.setHidden(false)
nameChange.setRequired(true)
}
else if(summ == 'Name Change for ALT- account'){
accountAssigned.setHidden(false)
accountAssigned.setRequired(true)
accountDeleted.setHidden(false)
accountDeleted.setRequired(true)
nameChange.setHidden(false)
nameChange.setRequired(true)
}
else if(summ == 'Tax Linux Access'){
uAssigned.setHidden(false)
uAssigned.setRequired(true)
}
else if(summ == 'Coordinate Employee Name Change'){
accountChange.setHidden(false)
accountChange.setRequired(true)
iscAccount.setHidden(false)
iscAccount.setRequired(true)
}
else if(summ == 'FastPass Access'){
adGroup.setHidden(false)
adGroup.setRequired(true)
}
else {
accountChange.setHidden(true)
accountChange.setRequired(false)
iscAccount.setHidden(true)
iscAccount.setRequired(false)
adGroup.setHidden(true)
adGroup.setRequired(false)
accountAssigned.setHidden(true)
accountAssigned.setRequired(false)
accountDeleted.setHidden(true)
accountDeleted.setRequired(false)
nameChange.setHidden(true)
nameChange.setRequired(false)
uAssigned.setHidden(true)
uAssigned.setRequired(false)
}

3 answers

2 accepted

0 votes
Answer accepted
Manoj Gangwar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 26, 2023

I figured it out, The Summary field was not added in the Screen that why it was not executing. 

0 votes
Answer accepted
Radek Dostál
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.
May 23, 2023

We don't know what you're missing, due to lack of context (what's not working? how is the behaviour configured?).

Assuming you did set it as an Initializer script, with the right project:issuetype mapping, then it should execute at all times on any screen, which includes create/edit/transitions.

So first thing you want to do is to restrict that scope to only run where you want it, so much like Graham suggested,

if (!getActionName().equals("Resolved"))
return // do nothing if we're not on Resolved transition

 

Second, if you're unsure about something, you can add some debugging. The most basic and quick to use is something like this:

getFieldById("description").setFormValue("My debug value: " + someVariable)

I think you could use the "comment" field if you're on a transition so then you can see what the values in those variables are when you want to double check that something does in fact work right. Otherwise you can also use the logger:

log.warn("Debug stuff: " + someVariable)

But then you need to grep the logs so while this can cover more things easily, you would need to open the logs (which scriptrunner has a built-in function for) and search for it.

 

What you also really want is to clean up that code, which should also improve performance a little bit, currently you have a ton of chained if elses, which is hard to read.

switch (summ) {
case "Something":
// do something
break
case "Something else":
// do something else
break
default:
// no other case fits? then use this branch
}

 

Otherwise I don't see any obvious error in the code, so either you did not set it up as an initializer script (thus it's not executing on the transition screen), or there is a typo/mistake somewhere, in which case you might want to add some debugging to check that all field / values are being read as you expect.

 

Edit:

Forgot one thing, the code executes line by line, so if it crashes (and stops executing the rest), you wouldn't necessarily know where it crashed exactly. But you can add stuff like 'log.warn("here 1"); log.warn("here 2")' etc. to different lines of code so you can narrow it down to the line that causes the script to crash. There are of course more technical ways to do so, but just using some made up trackers is quick and easy.

Manoj Gangwar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 23, 2023

Here is the configuration screenshot. Sam is configured for other issues types and it is working fine. I will follow the steps suggested by you. Thanksscren.png

Radek Dostál
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.
May 23, 2023

Ah, actually I see, it probably has a problem reading the Summary because you're hiding it.

So maybe it will help to remove that Summary->Hidden part, and instead hide it from the script itself after you read the value.

Maybe the Summary part is executed first and then your script is executed after it, which might be something to try.

Manoj Gangwar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 23, 2023

I just unhide the Summary but the issue is, Fields are not getting visible on Issue Transition Screen. For both type of issues eg. Summary== XYZ or Summary != XYZ.

Manoj Gangwar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 26, 2023

Hi @Radek Dostál ,

 

I figured it out, The Summary field was not added in the Screen that why it was not executing. 

0 votes
Graham Twine
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.
May 22, 2023

Hello @Manoj Gangwar ,

 

You are adding  this to a post function that has a screen right?

You can also include the transition action as well.

e.g.

 

if (getActionName().equals("Resolve")){

 

}

Manoj Gangwar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 22, 2023

Hi @Graham Twine , 

I added a scriptrunner behavior.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events