Check Custom Fields on Issues within an Issue Picker

David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 29, 2023

I have an Issue Picker custom field.

As part of a Post Function scriptrunner Groovy script i'm wanting to check if any of the issues within the Issue Picker have a specific field value, matching the same field from the parent issue.

The field is an Insight / Asset object field and i only need to return a true or false to determine if other actions are required.

My first thought is to dynamically create a JQL, validate and return to check if it has any values.

Key = ${ParentIssueKey} and issueFunction in issuePickerField('Problem Fixes', 'Source = ${ParentIssueSource}')

1 answer

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 9, 2023

Hi @David Harkins

In your description, you mentioned:-

I have an Issue Picker custom field.

As part of a Post Function scriptrunner Groovy script i'm wanting to check if any of the issues within the Issue Picker have a specific field value, matching the same field from the parent issue.

The field is an Insight / Asset object field and i only need to return a true or false to determine if other actions are required.

Based on what condition do you want to check if the issues in the Issue Picker have the same value as the Asset field? Is it based on the issues that have been selected from the Issue picker?

Please clarify.

Thank you and Kind regards,

Ram

David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 9, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

Imagine the Issue Picker has 3 issues selected.

I'd like to determine which of those three issues have specified value in a custom field

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 10, 2023

Hi @David Harkins

For your requirement, you could try something like this:-

import com.adaptavist.hapi.jira.issues.Issues
import com.atlassian.jira.issue.Issue

def assetsValue = issue.getCustomFieldValue('Assets') as String
def samplePicker = issue.getCustomFieldValue('Sample Picker') as List<Issue>
def result = false

samplePicker.each {
def selectedIssues = Issues.getByKey(it.key)
def cpu = selectedIssues.getCustomFieldValue('CPU')
if(assetsValue.contains(cpu)) {
result = true
}
}
log.warn "======>>>> ${result}"

Please note that the sample working code is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the Post-Function configuration:-

post_function_config.png

This code will read the values from the Asset / Insight field and compare it against the value of the CPU field, i.e. from the Issue(s) selected in the Issue picker and check if the Asset field contains the value of the CPU field. If yes, the result returned will be true; otherwise, the result will be false.

Below is a screenshot of the Assets used:-

asset_value.png

 

Below are some screenshots of the CPU text field from the Issues in the Issue Picker:-

issue_from_picker_1.pngissue_from_picker_2.png

Below is a screenshot of the issue comparison between the Assets field and the Issue Pickers:-

field_comparison.png

So, once the transition takes place if the Issues selected from the Issue picker contain the value of the CPU field that matches the Asset selected, the result returned will be true it will be false as shown in the screenshot below:-

log_output.png

 

I hope this helps to solve your question. :-)

Thank you and Kind regards,
Ram

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 12, 2023

Hi @David Harkins

Has your question been answered?

If yes, please accept the answer else please let me know.

Thank you and Kind regards,

Ram

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 19, 2023

Hi @David Harkins

Please confirm if your question has been answered.

If yes, please accept the answer.

Else, let me know if I have missed out anything and I will try to update the example.

Thank you and Kind regards,
Ram

Suggest an answer

Log in or Sign up to answer