My Jira version is 5.2.6 and Behaviours plugin is version0.5.3
I have a custom field that is called Production Cut-in that has a select list of Yes or No. If the user selects Yes I need to have another custom field called ECP marked as required, if the user selects no than the ECP field should not be required. I am new to groovy scripting and am not sure if I wrote the script correctly. Here is what I came up with:
FormField pro = getFieldById("customfield_11505") FormField ecp = getFieldById("customfield_11506") if(pro.getValue().contains('Yes')){ ecp.setRequired(true) }else{ ecp.setRequired(false) }
Any help would be greatly appreciated.
Thanks.
You can try this for newly added custom fields on issue screen (version 7.1)
import com.onresolve.jira.groovy.user.FormField
FormField test1 = getFieldByName("test")
FormField test2 = getFieldById("duedate")
String str=test1.getValue()
String str2=test2.getValue()
test2.setRequired(true)
test1.setRequired(true)
if(test1.getValue() == "1")
{
log.error("************ WELCOME in first loop ************")
test2.setRequired(true)
}
else
{
log.error("************ WELCOME in second loop ************")
test2.setRequired(false)
}
Hi Vidic,
how we can run above script for a specific project in jira?
do we need to create custom event for this or we need to use post-function?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can try also ...
FormField pro = getFieldByName("Name_of_f_no1_not_ID1") FormField ecp = getFieldById("Name_of_f_no2_not_ID2") String vpro = (String) pro.getFormValue() String vecp = (String) ecp.getFormValue() //to see values near fields uncomment sentences // pro.setHelpText("vpro: "+ vpro) //ecp.setHelpText("vecp: "+ vecp ) if (vpro == "Yes") { ecp.setRequired(true) }else{ ecp.setRequired(false) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Line 2 should be getFieldByName too I think...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
have you been able to find a solution?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You may want to consider also this solution for making a custom field required based on another custom field: http://confluence.kepler-rominfo.com/display/TR/Make+a+custom+field+required+based+on+another+custom+field, using the JJupin plugin and its Live Fields feature.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hrm, getValue() was introduced partly to avoid this need to look up an option by ID, or to hard-code an option ID, which makes it hard transferring code from dev to prod.
If you print the value that getValue() returns, you might find it's not a list, or it doesn't contain what you think.
Add
log.warn ("value returned was: " + pro.getValue())
Then tail your atlassian-jira.log, and refresh the page.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jamie,
I added the log.warn ("value returned was: " + pro.getValue()) and it said the value returned was null. Any ideas on this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Does getFormValue() return anything?
you should also
log.warn (pro)
to make sure the field is actually found...
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.
-1 sounds suspicious, that's not a valid option ID. What does log.warn(pro) say.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey,
I would use the option ID for the "Yeas" value e.g.:
if ((pro.getFormValue() == "12135") {
...}
Either way, you should use getFormValue() and not getValue() AFAIK.
Cheers
Christian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey,
I would use the option ID for the "Yes" value e.g.:
if ((pro.getFormValue() == "12135") {
...}
Either way, you should use getFormValue() and not getValue() AFAIK.
Cheers
Christian
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.