• Community
  • Products
  • Marketplace Apps
  • Questions
  • Is there any plugin or any feature in JIRA wherein we have 2 fields and the plugin allows us to choose a field among the two. So out of the 2 mandatory fields one of the field needs to be selected

Is there any plugin or any feature in JIRA wherein we have 2 fields and the plugin allows us to choose a field among the two. So out of the 2 mandatory fields one of the field needs to be selected

We have a scenario where in we have to include users and groups. But i am not sure if there is any field which allows to include user picker as well as group picker into a single field. So what we have done is that we have 2 separate fields - one for user picker and another for group picker. But among the two we need to select only one. But we need to pick one field since out of the two selecting one is mandatory

3 answers

1 accepted

This widget could not be displayed.

i suggest write your own validator using java or using script runner plugin

https://jamieechlin.atlassian.net/wiki/display/GRV/Validators

I did try to create such validator bu looking into scripts from jamie. I am stuck in between. I have posted the code below

import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def issue = ComponentAccessor.getIssueManager().getIssueObject("TESTING-3")
CustomField group = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12510")


CustomField ppl = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10141")

def pplVal = issue.getCustomFieldValue(ppl)
def groupVal = issue.getCustomFieldValue(group)

------------------------------------------------------------------------------------

I have to compare these fields if they are null like

if(pplVal=="" or groupVal=="")

{

// Throw some exception that atleast one should be filled

}

------------------------------------------------------------------------------------

But i am not getting the proper syntax for the above code. if i directly compare them then i get no return value and if i add pplVal.value == "" then i get "Cannot get property 'value' on null object". Can someone please help me in completing code.

Note pplVal is a user picker and groupVal is group picker

i think you can use simple script something like this

if(cfValues['customfield_12510'] && cfValues['customfield_10141']){

//throw exception here

}

check this

https://answers.atlassian.com/questions/213435/script-validator-custom-field-value?page=1#213994

ine more thing from your code,

you have to put condition something like this

if(pplVal==null && groupVal==null)

because if the both field not selected then you need to through error correct?

Hi Prasad, i dont know where i am going wrong. But still this code isnt working.

I have written it as

cfValues['customfield_12510']==''
Even when the field has value or not this get fired and i 
cant proceed. Its a group picker field, does syntax changes ?
 
Secondly how will you write or condition for the above. I want 
atleast one of it to be checked. 
 
Please help
 
cfValues['Name of field']
 
is sufficient for the simple scripted validator. Note that null does not equal an empty string
 
 

Hi Jamie, i did try , but it gets fired everytime.

This widget could not be displayed.

This can be easily resolved creating a new Custom Field Type. There you can design the html of your new custom field and the logic behind it (java code). That way you will have the freedom to design your custom field exactly the way you want it to be.

This widget could not be displayed.

Hi Jamie, does this script work even for multi user picker or multi group picker field? I have a state in workflow "Submit". There i have added the script cfValues['customfield_12512']. This gets fired when we have not chosen any user in the user picker field which is correct. But even when we pick some users we see the same error reappearing. I was assuming that this error will disappear. Am i missing something?


Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

523 views 3 19
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you