Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If you want the specific Checklist appended to your newly created ticket depending on the other Custom field value - you can easily do it by adding Script Runner Post Function to your Create Ticket workflow transition.

Check it out!

Assume that you have a custom field named "Environment" with 2 values: Production/Staging. So you expect that while adding a new issue - you'll have a proper checklist assigned

Image Added

Result

Image Added


Here's an implementation flow


  1. Go To Workflow Editor
  2. Choose "Script Post Function" Script Runner

    Image Removed

    Image Removed
  3. Choose "Custom Script Post Function"

    Image Added

  4. Add inline Script
    Image Added



  5. Variables checklistProd and checklistStage used for keeping the proper value of the checklist (in text format)

    Code Block
    languagegroovy
    themeMidnight
    titleScriptRunner
    import com.atlassian.jira.component.ComponentAccessor
    import com.atlassian.jira.issue.ModifiedValue
    import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
    import org.apache.log4j.Level
    
    log.setLevel(Level.DEBUG)
    
    //Grab necessary Components
    def cfm = ComponentAccessor.getCustomFieldManager()
    def optionsManager = ComponentAccessor.getOptionsManager()
    
    def cfEnv = cfm.getCustomFieldObjectByName("Environment")
    def cfEnvtValue = issue.getCustomFieldValue(cfEnv)
    def cfEnvValueString = cfEnvtValue.toString()
    def changeHolder = new DefaultIssueChangeHolder()
    
    def checklistProd = "- ToDo List\n+ Checked\nx Skipped\n~ In Progress\n# Another ToDo List\n- Unchecked\n> Quote line 1 https://rw.rw\\n> Quote line 2\n> Quote line 3\n"
    def checklistStage = "- Uno\n+ Dos\nx Tres\n~ Quatro\n"
    
    
    log.info("checklistProd: " + checklistProd)
    log.info("checklistStage: " + checklistStage)
    log.info("Environment"+ cfEnvValueString)
    
    
    if (cfEnvValueString == "Production") {
    	//Set custom text field
    	def cfClient = cfm.getCustomFieldObjectByName("Checklists")
    	issue.setCustomFieldValue(cfClient,checklistProd)
    } else if (cfEnvValueString == "Staging") {
    	//Set custom text field
    	def cfClient = cfm.getCustomFieldObjectByName("Checklists")
    	issue.setCustomFieldValue(cfClient,checklistStage)
    }
    
    
  6. Image Removed
  7. Image Removed

  8. Result

    Image RemovedSave the script. IMPORTANT! Make the Post Function is placed as a #1 Step!
    Image Added




Insert excerpt
Support
Support
nopaneltrue

...