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)
}
I figured it out, The Summary field was not added in the Screen that why it was not executing.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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. Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Radek Dostál ,
I figured it out, The Summary field was not added in the Screen that why it was not executing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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")){
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Graham Twine ,
I added a scriptrunner behavior.
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.