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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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;
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 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 }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi R Prasad
Thanks for the reply, i tried with this code, i still get error msg, when custom filed is NOT null!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
can you share what is the error message you are getting?
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 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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
is there any validators/functions configured on that transitions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i tried with Prasad code as a behaviour, it did not show any msg to user, when custom field is empty.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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*
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try the two parts separately in the admin -> built-in scripts -> condition tester.
That I was quick was just pure coincidence by the way.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's just a variation on the above. What have you tried so far?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If Patch Type is a select list, it should be:
cfValues['Patch Type'].value == 'Patch'
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.