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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
cfValues['Name of field']
is sufficient for the simple scripted validator. Note that null does not equal an empty string
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie, i did try , but it gets fired everytime.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
debugg with power assertions
https://jamieechlin.atlassian.net/wiki/display/GRV/Built-In+Scripts#Built-InScripts-PowerAssertions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.