how to validate custom field(user picker filed) with simple script validator

Hi

Using simple script validation, i want to validate if a custom field(user picker field) is empty, show error message.

I tried below code, it always shows msg, even when customfield has user in it.

cfValues['customfield_10000'] = null

I tried many combinations of above with custom field name etc, still same issue.

Thanks

5 answers

1 accepted

This widget could not be displayed.

With a simple scripted validator, you just need:

cfValues['customfield_10000']
If you want to ensure it's empty use:
! cfValues['customfield_10000']
 
 
 
 

Jamie

I tried with this script -

cfValues['customfield_10000']

it gives message even there is value in custom field( user picker field)

this script -

! cfValues['customfield_10000']

does not give any message, if there is no user in custom field

Jamie

Thanks for quick response, sorry if there was any confusion.

Let me explain the scenario :

while doing the transition, check the validation

If CR user( customfiel_10000) is empty, show msg to user to select a user in custom field, and dont allow the tranisition.

If CR user already there in field, dont show a msg, allow the transition.

This widget could not be displayed.

@Jamie Echlin [Adaptavist],

I am using the script validator on the create transition and I want to build my condition based on the value of a user picker custom field and another select list custom field. I have two problems, the first is how to capture the value of the custom field on create transition and how to compare the value of the user picker custom field to a certain value. My script should be in this form:

if (cfValues['Some Custom Field'] == 'Some Value' and cfValues['user picker field'] != 'xxx') return false; else return true;

This widget could not be displayed.

i think you have to try some think like this

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.crowd.embedded.api.User

 
MutableIssue issue = issue
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
CustomField customField = customFieldManager.getCustomFieldObject("User Custom field Name")

def fieldVal = issue.getCustomFieldValue(customField)
   if(fieldVal == null ){
  //throw error message here
   }

Hi R Prasad

Thanks for the reply, i tried with this code, i still get error msg, when custom filed is NOT null!!

can you share what is the error message you are getting?

Hi Prasad

I am using JIRA 6.0.2, here is the catalina.out error.

on screen, it shows message " A Code reviewer must be assgined before intiating code review" even when code reviewer is present in the field( not null), not able to tranistion issue with message.

2013-09-06 11:34:39,294 http-bio-9000-exec-41 ERROR xxxxxx 694x76840x1 1tnseum 197.1.18.83 /secure/CommentAssignIssue.jspa [atlassian.jira.workflow.OSWorkflowManager] Caught exception while attempting to perform action 881 from workflow 10641 on issue 'DEV-74'

[InvalidInputException: [Error map: [{}]] [Error list: [[A Code reviewer must be assgined before intiating code review]]]

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)

at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:71)

at org.codehaus.groovy.runtime.callsite.ConstructorSite.callConstructor(ConstructorSite.java:42)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)

at com.onresolve.jira.groovy.canned.workflow.validators.SimpleScriptedValidator.doScript(SimpleScriptedValidator.groovy:66)

is there any validators/functions configured on that transitions?

NB - rambanam's answer relates to using a standalone groovy script. With the "simple scripted validator" you just provide a statement that evaluates to either true or false, and provide the error message. You don't need to worry about throwing the exception.

@Prasad

There are no other validations on this transition. this is onky validation i was adding as a simple script validation in that transition.

@ Jamie

oh ok, let me try with groovy script

i tried with Prasad code as a behaviour, it did not show any msg to user, when custom field is empty.

This widget could not be displayed.

Maybe it s a good place to add my question here as we want to check something very similar:

If one custom field (Patch Type) is of a specific value (Patch) another custom field (CEMLI) is not allowed to be empty. In case the expression is true prevent of the transition (Create Issue) and show a message (Please choose according CEMLI) to the user.

cfValues['Patch Type'] == 'Patch' && ! cfValues['CEMLI']

The result of this is that no issue can be created as the message is shown at any combination of values. Anybody an idea what to be changed?

If Patch Type is a select list, it should be:

cfValues['Patch Type'].value == 'Patch'

This widget could not be displayed.

Hey Jamie,

thanks for being quick, but unfortunately this don t work! I adapted your suggestion to the one below as CF-Type of "Patch Type" is single select list, the CF "CEMLI" is of Type "Select List (multiple choices)".

cfValues['Patch Type'].value == 'Patch' && ! cfValues['CEMLI'].value

This expression blocks everything, i assume the expression doesn t match to the multi-select list?!

Update: Tested with only

cfValues['Patch Type'].value == 'Patch'

doesn t block anything... *confused*

Try the two parts separately in the admin -> built-in scripts -> condition tester.

That I was quick was just pure coincidence by the way.

I have multi select list custom field. If i select perticular option script should make two fields required on same screen.How we can achive this.

It's just a variation on the above. What have you tried so far?

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

195 views 3 0
Join discussion

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