• Community
  • Products
  • Apps & Integrations
  • 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

Jayashree Shetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 1, 2013

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

0 votes
Answer accepted
RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 2, 2013

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

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

Jayashree Shetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 19, 2013

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

RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 19, 2013

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

RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 19, 2013

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?

Jayashree Shetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 19, 2013

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
 
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 19, 2013
cfValues['Name of field']
 
is sufficient for the simple scripted validator. Note that null does not equal an empty string
 
 
Jayashree Shetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 22, 2013

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

RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 22, 2013
0 votes
Jayashree Shetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 22, 2013

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?


0 votes
MB
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 2, 2013

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events