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

How can we write script in script runner in jira for workflow validators

Hi ,

I want to write script in script runner for workflow in between transition for validators to check the issue link is enter or not (tested by OR created by) any one of link has to enter in the transition.

So please let me know your inputs and help me out.


Thanks in advance,



2 answers

0 votes

There are some useful examples of validators at

Hi, @syamala yerramsetty 

It would be something like this (you should add this as condition in a simple script validator):


import com.atlassian.jira.component.ComponentAccessor

if ( == 'Tarea IT'){   //checks the issuetype in case you don't want to apply to everyone
if (cfValues['linked issues']) return true;  //You have to check here the kind of links

return false;

return true

Hi  fran garcia gomera,

Thanks for your input.

I have written below code in script runner but getting error in 4th line "Linked Issues" that field does not exists or multiple field exists for the same name.

import com.atlassian.jira.component.ComponentAccessor

if ( == 'Story'){   //checks the issuetype in case you don't want to apply to everyone
if (cfValues['Linked Issues']) return true;  //You have to check here the kind of links

return false;


return true

So could please help me out.



@syamala yerramsetty 

My bad, i gave half the solution.

We had to use a workaround. I try to explain it completely.

The trouble is that you can't check as a validator the linked issues, there is no information until the issue is created.

The workaround was adding a new field, check that field in the validator with the code i added there and then copy the value of that field as a postfunction with the issueLink Manager.

Step by step

  1. create a new field (in the code is that one called 'Linked Issues') of type single issue picker.
  2. Add it to the create screen of your workflow.
  3. Add a new validator (simple script validator : in the condition add the code and in the Field select select 'Linked Issues' field)  in the create transition.
import com.atlassian.jira.component.ComponentAccessor


if ( == 'Story'){
if (cfValues['Linked Issues']) return true;

return false;

return true 

with this, that field is required for the issuetype you need in case you need to apply only to some issue types.

4. Create a postfunction with this script

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager

//uncomment to check in console
//def issueManager = ComponentAccessor.getIssueManager()
//def issue = issueManager.getIssueObject("AE-82")

//end of check in console

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def userManager = ComponentAccessor.userManager
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.getIssueManager()

CustomField field = customFieldManager.getCustomFieldObjectByName('Linked Issues')
def clave = field.getValue(issue).toString()
def issueenlazada = issueManager.getIssueObject(clave)
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();

issueLinkManager.createIssueLink(issue.getId(), issueenlazada.getId(), 10400, 1, user)

 That 10400 on the last line is the type of link you want that issuelink to be, in my case complements. This is the complete list

10000Blocksis blocked byblocks 
10001Clonersis cloned byclones 
10002Duplicateis duplicated byduplicates 
10003Relatesrelates torelates to 
10200Epic-Story Linkhas Epicis Epic ofjira_gh_epic_story
10300Gantt End to Starthas to be done afterhas to be done before 
10301Gantt Start to Starthas to be started together withhas to be started together with 
10302Gantt End to Endhas to be finished together withhas to be finished together with 
10303Gantt Start to Endstart is earliest end ofearliest end is start of 
10400ComplementsIs complemented byComplements 
10500Problem/Incidentis caused bycausesservicedesk_automation_default_linktype

And that's all.

A little bit messy but it's working for me.

Sorry i gave you false hope of this being very much easier

Suggest an answer

Log in or Sign up to answer

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