Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner script for finding Issues with same Field Value and Link to newly created issue

uvo3 main public name
Contributor
July 6, 2023

I have a Field for two issue types (A , B) in a project. It is a Select List (single choice) type custom Field.

If Value of Field matches with other issue of B issue type that issue has to link to the current created issues automatically.

Please help me with Scriptrunner script code for listener.

1 answer

1 vote
Florian Bonniec
Community Champion
July 6, 2023

Hi @uvo3 main public name 

You could use automation for JIRA to listen the Field change then run a scriptrunner action that will get all issues that have the value and not linked yet.

 

You could use a script like this one to achieve what you are looking for 

String issueKey = issue.key

String fieldValue = ruleContext.renderSmartValues('{{issue.customfield_XXX}}') // XXX is your customfield id

Issues.search('field = ${fieldValue} and type = B and project = XXX and issueFunction not in linkedIssuesOf("key = ${issueKey}")').each { issue ->

    Issues.getByKey(issueKey).link('linkName', issue)

}

Regards

uvo3 main public name
Contributor
July 7, 2023 edited

Thank you for your response.
Could you please explain how to set up automation in Jira server 8.13.2 with Scriptrunner onboard.

The workflow: ticket created in issue type A has customfield1 value TEST,
One of existing ticket of issue type B has the same value TEST in customfield1
How to find and link first ticket with second on the tciket creation stage?
How to update a couple of fields in new created ticket from linked ticked.

Please help me with Scriptrunner script code.



Florian Bonniec
Community Champion
July 7, 2023

Hi

I usually use Autoamtion to reduce as much as possible the code to write but everything could be done by Scriptrunner.

 

You could create an Automation for JIRA that is an app included in JIRA or Free if you are using a Data Center version.

Create an automation with Field value changed as trigger, then select the field customfield1.

You can then add condition in the rule to make sure the issue type is A etc..

Then as action you can add Scriptrunner, it should be available if you have it installed.

In the script section that will be displayed, you can adapt the code I pasted on my previous message.

 

Regards

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.13
TAGS
atlassian, jira cloud certification, managing jira projects, jira project administration, jira cloud exam, atlassian certification, agile project management, jira workflows, jira permissions, jira training, jira cloud skills, atlassian learning

Become a Certified Jira Service Project Expert 🦸🏻‍♂️

Validate your expertise in managing Jira Service Projects for Cloud. Master configuration, optimize workflows, and manage users seamlessly. Earn global 🗺️ recognition and advance your career as a trusted Jira Service management expert.

Get Certified! ✍️
AUG Leaders

Atlassian Community Events