It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Script runner validation with multiple fields does not work Edited

The problem

Hi I am trying to write a script runner simple validator script which validates two fields

What I am trying to do is to check if at least one of them was selected

The customer is multi-select and the Device Related is single select

both are getting the data from Insight objects

 

Steps I did

This is what I am trying to do

cfValues['Customer'] || cfValues['Device Related']

In this case, I can not create the issue

 

Using only  cfValues['Customer']

Works for customer field (validation works as expected)

 

Edit

cfValues['Device Related'] alone does not work

I could not find anything in the logs can someone direct me the correct log or what to look for

 

image.png

any ideas?

 

1 answer

1 accepted

0 votes
Answer accepted
Antoine Berry Community Leader Sep 11, 2019

Hi @Nehemia Litterat ,

I just tried this exact code using Insight fields and it is working as expected. Have you tried all cases and identified which ones work/do not work ? Have you checked the logs ?

Antoine

Thanks for the quick reply

The cases are very simple :)

During the create I am trying to save the issue with values 

By the way, something I did not write in the original question is that 

cfValues['Device Related']

alone does not work

This is customer env I asked for logs I should get them tommorrow

I will update if I will find something there

It is good to know that my script is valid 

I edited the original question

In short, the logs do not show anything

I would be good to know what to look for or in which log to look into

I looked in the application logs 

We have two custom fields with the same name

only one of them is present on the screen

image.png

Ok so this is the problem 

it seems that the issue is that I have two custom fields with the same name 

Again only one is on the screen

the reason we did that was to have one for single value select and other is for multi-value select

 

any ideas?

I see, you will need to use the ids then : 

import com.atlassian.jira.component.ComponentAccessor

int insightId1 = 12001
int insightId2 = 12002
def insightValue1 = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject(insightId1))
def insightValue2 = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject(insightId2))

insightValue1 || insightValue2

As a rule of thumb I strongly disadvise to use two custom fields with the same name. It can quickly become confusing in the scheme configurations, backups, and can mess up your code.

That is also why I recommend to always use id in the code, so that you can rename the custom field without consequence.

Antoine

Thanks, I took your advice 

deleted the second field 

and now I will add validation for choosing only one value 

Like Antoine Berry likes this

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

The add-in you’ve been waiting for: Jira Cloud for Excel 🙌

Introducing Jira Cloud for Excel Here at the product integrations team at Atlassian, we are thrilled to announce the new Jira Cloud for Excel add-in! This add-in lets you export Jira data directly ...

841 views 5 22
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you