Integrate Custom Script as Post Function for Issue Transitions in Workflow

Nadir Jabbarli
Contributor
November 11, 2024

I would like to write a few new post functions. These post functions will include 3-4 custom fields, and based on the selections within these fields (select type), I would like to transition to the necessary status. Could you assist with the scripting for this?

"The 'Transition issue based on the following parameters' post function works. However, I believe my JQL query is too large (3-4 minimum condition (customField_XXX = "Test", and etc), so it may be unable to handle it effectively. I think the 'Fast-track transition an issue' post function could resolve this immediately. I just need assistance with writing the script in a way that can handle it. Thank you!"

1 answer

1 accepted

0 votes
Answer accepted
Bobby Bailey
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.
November 13, 2024

Hi @Nadir Jabbarli , 

As you have mentioned, this is something you can definitely do with ScriptRunner's fast track post function feature. 

For the script, its quite simple to check values, you just need to handle them correctly. Here is an example script that give you examples on how you can handle the following: 

  • System fields (I use priority)
  • Custom text fields
  • Custom number fields
  • Custom single select fields
  • Custom multi select fields

 

def priorityValue = issue.getPriority().id
def customTextFieldValue = issue.getCustomFieldValue('Custom Text Field')
def customSingleSelectValue = issue.getCustomFieldValue('Custom Single Select')
def customNumberFieldValue = issue.getCustomFieldValue('Custom Number Field')
def customMultiSelectValue = issue.getCustomFieldValue('Custom Multi Select') as Map

boolean priorityValid = (priorityValue == "3") // ID for medium prio
boolean textValueValid = (customTextFieldValue == "Test")
boolean singleSelectValueValid = customSingleSelectValue.any { it.value == "1"}
boolean numberValueValid = (customNumberFieldValue > 10)

def requiredValues = ['2', '3']
boolean multiSelectValueValid = requiredValues.every { requiredValue ->
    customMultiSelectValue.any { it.value == requiredValue }
}

if(priorityValid && textValueValid && singleSelectValueValid && numberValueValid && multiSelectValueValid){
    return true
} else {
    return false
}



Let me know if this helps!

Kind regards, 

 

Bobby

Suggest an answer

Log in or Sign up to answer