You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi all, I'm looking for help for a groovy script, which is not what I'm best at :)
In a transition from A to B, I would like to compare two fields:
Vendor: Insight Referenced Object (single) / Custom field
Product: Select List (single choice) / Custom field
The simple scripted validator should check, if Product is filled out, if Vendor equals certain values ("Supplier (A)" or "Supplier (B)"). If Vendor has any other value than these two, Product doesn't have to be filled out.
I have tried with various examples of this script:
def cfVendor = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10806").toString()
def value1 = issue.getCustomFieldValue(cfVendor)?:"" as String
def cfProduct = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_14302").toString()
def value2 = issue.getCustomFieldValue(cfProduct)?:"" as String
if(value1 == "Supplier (A)" && value2 == null)
It's almost never a good idea to coerce an object (like custom field object or insight object bean object) to a string.
Better find the correct method for that object to get the desired info.
Here is a script that should work for you
//this allows importing ObjectBean above, and helps with autocomplete and static type checking
def vendorObjects = cfValues['Vendor']
if(!vendorObjects) return true //nothing to validate if vendor is empty. Return false, if the field is required, or mark is required in another validator to have a different message
//jira always returns a list even when multiple is not allowed, so assume we want the first and only value in the list
def vendorObject = vendorObjects.first() as ObjectBean
def productRequiredVendors = ['Supplier (A)', 'Supplied (B)'] //don't include the key, just the display label.
if(!productRequiredVendors.contains(vendorObject.label)) return true //don't validate the product, the current vendor is not in the list
//if we're still running (no return true encountered), check the product
def product = cfValues['Product']
return (product) //this will be true if product is filled in or false if it wasn't
Note that cfValues is only available in simple scripted validators and simple scripted condition (perhaps also in some postfunctions). But not in custom script validators and conditions. IN those, then you need to use customFieldManager. But not here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.