I am trying to set two behaviors, but it is very hard because I do not have any coding background. The idea is that the ticket creation screen would hide/show fields depending on what the user chooses.
So the first behavior should be from a dropdown menu with 3 options (SAP, Jira, Other) and the dropdown menu's name is Affected Software. If the user chooses SAP, a textfield to appear which is called Transaction number. If they choose other, another textfield should appear called Please enter software name and otherwise, these should be hidden and not show any other fields.
Here is the code I tried to write:
import com.onresolve.jira.groovy.user.FormField
FormField dropDown = getFieldByName("Affected Software")
FormField other = getFieldByName("Transaction Number")
FormField other = getFieldByName("Please enter software name")
if (dropdown.getFormValue() == 'SAP') { other.setHidden(false) other.setFormValue("SAP chosen")
} if else (dropdown.getFormValue() == "Other") other.setHidden(false)
other.setFormValue("Other chosen")
else { other.setHidden(true)
}
The second behavior is a bit simpler. There is again a dropdown field called Is there a workaround with these options(yes, no, I don't know). If the user chooses yes, a field should show up called Explain the workaround. Otherwise nothing should change.
This is the code I tried to write for that one
import com.onresolve.jira.groovy.user.FormField
FormField dropDown = getFieldByName("Is there a workaround?")
FormField other = getFieldByName("Explain the workaround")
if (dropdown.getFormValue() == 'yes') { other.setHidden(false) other.setFormValue("yes chosen")
} else { other.setHidden(true)
}
Could you please let me know what I am doing wrong? Thank you in advance!
Hello @[deleted] ,
There is a couple of things that could cause the first one not to work.
Here is what the code should look like :
import com.onresolve.jira.groovy.user.FormField
def dropDown = getFieldByName("Affected Software")
def other1 = getFieldByName("Transaction Number")
def other2 = getFieldByName("Please enter software name")
if (dropDown.getFormValue().toString() == 'SAP') {
other1.setHidden(false)
other1.setFormValue("SAP chosen")
}
else if (dropDown.getFormValue().toString() == "Other") {
other2.setHidden(false)
other2.setFormValue("Other chosen")
}
else {
other1.setHidden(true)
}
Let me know if this works for you or if you need more help.
Best regards,
JT
Thank you so much JT!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
However, the code is still not working :/ Any ideas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you have any errors? Or is the behavior just not working?
Did you add the script as an initializer or to the field itself?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is just not working, I tried first to the server-side script below the condition and then in the initializer.
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 solution if anyone else needs it
def field = getFieldByName("Standards")
def otherField = getFieldByName("Other")
if(field.getValue() == "MyCoolValue"){
otherField.setHidden(true).setRequired(false).setFormValue("")
} else{
otherField.setHidden(false).setRequired(true)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.