Script runner validation with multiple fields does not work

Nehemia Litterat September 11, 2019

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 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

Nehemia Litterat September 11, 2019

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 

Nehemia Litterat September 12, 2019

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 

Nehemia Litterat September 12, 2019

We have two custom fields with the same name

only one of them is present on the screen

image.png

Nehemia Litterat September 12, 2019

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?

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 12, 2019

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

Nehemia Litterat September 12, 2019

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