Validator condition if Insight custom filed value is in particular Object type

Andrey Kolesnikov December 2, 2020

Hi!

I have several Object Types in my Insight with different Objects in them, e.g.:

Servers

 - server1

 - server2 etc

Switches

 - switch1

 - switch2 etc

And i have an Insight custom field in each issue, where you should choose an Object linked to it.

So i want to implement a Validator, that certain field was required, but ONLY if an Object in my custom filed was in particular Object type. 

For example, text field "VLAN" should be required only if Object chosen was in Object type "Switches"

So i choose a Validator in workflow, choose "Fields Required Validator (JMWE app)" and say that "VLAN" field should be required on this transition. And check 'conditional validation' checkbox. System offers me to type a Groove expression for the condition. I tried 

issue.get("customfield_10501") in iqlFunction("objecttype = \"Switches\"")

like i do in JQL, but that doesnt work. Please advice

1 answer

1 accepted

1 vote
Answer accepted
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 2, 2020

Hi Andrey,

we do have in our backlog JQL-based Conditions and Validators, but this will only work if the JQL "filter" depends only on values before the transition screen. Because JQL uses the Jira index, which is not updated with values entered on the transition screen. So in your case it would never work, since you're testing two fields that are being modified on the transition screen.

However, you can implement the conditional validation in Groovy, although Insight's Java API doesn't make it particularly easy.

issue.get("customfield_10501")[0].objectTypeId == 23

where 23 is the object type ID. Unfortunately, I'm unable to test this right now, but you get the idea.

Andrey Kolesnikov December 2, 2020

Yeah, after some more deep investigations i have also found the proper code, but you have shown me the way, thanks!

 

issue.get("customfield_10501")?.first()?.objectTypeId == 38

Suggest an answer

Log in or Sign up to answer