User Tools

Site Tools


script_fields

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
script_fields [2018/07/13 12:12]
root Added testRadio change reference
script_fields [2019/07/11 09:28] (current)
root
Line 36: Line 36:
 </code> </code>
  
-==== Return user that made last change on field "testRadio" ====+ 
 +==== Drop Down Values based on Transitions ==== 
 +Create this as an initialiser.
 <code java> <code java>
 import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.component.ComponentAccessor
 import static com.atlassian.jira.issue.IssueFieldConstants.* import static com.atlassian.jira.issue.IssueFieldConstants.*
  
-def changedItem = ComponentAccessor.getChangeHistoryManager().getAllChangeItems(issue)?.findAll {it.field == "testRadio"}?.last()+def customFieldManager = ComponentAccessor.getCustomFieldManager() 
 +def optionsManager = ComponentAccessor.getOptionsManager()     
 + 
 +def formField = getFieldByName("FIELD_NAME") // *name* of your custom field 
 +def customField = customFieldManager.getCustomFieldObject(formField.getFieldId()) 
 +def config = customField.getRelevantConfig(getIssueContext()) 
 +def options = optionsManager.getOptions(config) 
 + 
 +// Set the values inside the select list field  
 +def noneMap = ["-1": "None"
 + 
 + 
 +if (getActionName() == "Need More Info") { 
 +    def optionsMap = noneMap + options.findAll { 
 +        it.value in ["OPTION 1", "OPTION 2", "OPTION 3"] // list of options you want to show 
 +    }.collectEntries { 
 +        [ 
 +            (it.optionId.toString()) : it.value 
 +        ] 
 +    }  
 +    formField.setFieldOptions(optionsMap) 
 +} else if (getActionName() == "Resolved") { 
 +    def optionsMap = noneMap + options.findAll { 
 +        it.value in ["OPTION 1", "OPTION 3"] // list of options you want to show 
 +    }.collectEntries { 
 +        [ 
 +            (it.optionId.toString()) : it.value 
 +        ] 
 +    }  
 +    formField.setFieldOptions(optionsMap) 
 +} else if (getActionName() == "Close") { 
 +    def optionsMap = noneMap + options.findAll { 
 +        it.value in ["OPTION 4", "OPTION 5"] // list of options you want to show 
 +    }.collectEntries { 
 +        [ 
 +            (it.optionId.toString()) : it.value 
 +        ] 
 +    }  
 +    formField.setFieldOptions(optionsMap) 
 +} else { 
 +    def optionsMap = noneMap + options.findAll { 
 +        it.value in ["OPTION 3"] // list of options you want to show 
 +    }.collectEntries { 
 +        [ 
 +            (it.optionId.toString()) : it.value 
 +        ] 
 +    }  
 +    formField.setFieldOptions(optionsMap)     
 +}
  
-return "${changedItem?.getUserKey()}" 
 </code> </code>
-Reference: [[https://community.atlassian.com/t5/Jira-questions/Script-runner-to-pull-user-details-for-last-field-data-change/qaq-p/591202|Pull User Details for field data change]]+References 
 +[[https://gist.github.com/jechlin/d9b8e778041c02e04270|GitHub Link]] 
 +[[https://community.atlassian.com/t5/Adaptavist-questions/Scriptrunner-behaviour-Setting-select-list-options-None-is-not/qaq-p/934238|Atlassian Community Link]] 
 + 
script_fields.1531498362.txt.gz · Last modified: 2018/07/13 12:12 by root