We want to set a automate producer where one fields get filled others 2 fields will be mandatory or vice-versa.
Can we set a rule so that one of the 3 fields (Wiser Case #, Task ID, Customer Name(s)) is populated all others will be required as well?
Hi @Rajiv Ranjan ,
This is possible indeed. Add a behaviour script to each one of these fields. For example on field 1, you would use this :
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def cf1_id = 10100
def cf2_id = 10101
def cf3_id = 10102
def cf1 = getFieldById("customfield_"+cf1_id)
def cf2 = getFieldById("customfield_"+cf2_id)
def cf3 = getFieldById("customfield_"+cf3_id)
def cf1Value = cf1.getValue()
if (cf1Value != null){
cf2.setRequired(true)
cf3.setRequired(true)
}
Of course you can change the condition.
Antoine
Hello @Antoine Berry ,
Thank you for the code and suggestion!!!
Update the code you provided with the respective customfield_id and added the code to a server-side script to the "Wiser Case#" field i.e. first field however while creating the ticket others two fields are mandatory without putting any value to the first field which is wrong.
I need after putting some value to the first field others two fields should be mandatory.
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.
Ah, you just need to tweak the behaviours a bit. First I would suggest to make the fields optional in the field configuration. Then just add an "else" statement :
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def cf1_id = 10100
def cf2_id = 10101
def cf3_id = 10102
def cf1 = getFieldById("customfield_"+cf1_id)
def cf2 = getFieldById("customfield_"+cf2_id)
def cf3 = getFieldById("customfield_"+cf3_id)
def cf1Value = cf1.getValue()
if (cf1Value != null){
cf2.setRequired(true)
cf3.setRequired(true)
}
else {
cf2.setRequired(true)
cf3.setRequired(true)
}
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The fields are optional but different types.
As suggested after checking the fields configuration I have inserted the new code however the same result. Without putting any value to 1st field the other two fields are mandatory.
Later on, updated the code as its look like returning the same value in If or else condition.
{code}
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def cf1_id = 10001
def cf2_id = 10002
def cf3_id = 10003
def cf1 = getFieldById("customfield_"+cf1_id)
def cf2 = getFieldById("customfield_"+cf2_id)
def cf3 = getFieldById("customfield_"+cf3_id)
def cf1Value = cf1.getValue()
if (cf1Value != null){
cf2.setRequired(true)
cf3.setRequired(true)
}
else {
cf2.setRequired(false)
cf3.setRequired(false)
}
{code}
Please assist here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Rajiv Ranjan ,
Maybe that is because the cf1Value is not null even if the field is empty (if it is a text field for example). You need to test the script (with logs) for each field to make sure this is working the way you intend.
Try to update the script to :
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def cf1_id = 10001
def cf2_id = 10002
def cf3_id = 10003
def cf1 = getFieldById("customfield_"+cf1_id)
def cf2 = getFieldById("customfield_"+cf2_id)
def cf3 = getFieldById("customfield_"+cf3_id)
def cf1Value = cf1.getValue()
log.error("cf1Value : " + cf1Value)
log.error("cf1Value class : " + cf1Value.getClass())
if (cf1Value != null && cf1Value != ""){
cf2.setRequired(true)
cf3.setRequired(true)
}
else {
cf2.setRequired(false)
cf3.setRequired(false)
}
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Antoine,
Since it is multi-text field cf !="" works.
Now if part working fine but else part when we clear Task Id (Text Field (single line))value the Wiser_Case# does not marked optional
//Get a FormField object to retrieve the value.
def Wiser_Case_No = getFieldById("customfield_11101")
def Customer_Names = getFieldById("customfield_10804")
def Task_ID = getFieldById("customfield_10600")
//Gets the value from the field
def Wiser_Case_NoValue = Wiser_Case_No.getValue()
def Task_IDValue = Task_ID.getValue()
//Error log
log.error("Task_IDValue : " + Task_IDValue)
log.error("Wiser_Case_NoValue : " + Wiser_Case_NoValue)
//If Wiser Case# not empty or Task ID not empty then Customer name is mandatory.
if ((Task_IDValue != "") || (Wiser_Case_NoValue != ""))
{
Customer_Names.setRequired(true)
}
else
{
Customer_Names.setRequired(false)
}
//If task ID is not empty then Wiser Case # is mandatory
if (Task_IDValue != "")
{
Wiser_Case_No.setRequired(true)
}
else
{
Wiser_Case_No.setRequired(false)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Rajiv Ranjan ,
What custom field type is Task ID ? Maybe you need to compare against null instead of "" (if it is a number for example). Otherwise it looks fine :)
Antoine
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.
At first glance it should work with text field. What do you get in the logs for "Task_IDValue" ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Antoine,
Separate the behavior script for each of the fields, now it working as expected.
Thank you so much for your guidance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad to help ! Indeed, you need to map the script to the field that will "listen" (i.e. trigger) to it. Please consider accepting the answer if you are satisfied with it. :)
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.