This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
post_functions [2018/01/12 09:26] pawel [Update Fix Version/s field with first Unreleased version if there isn't a version already there or give error message] |
post_functions [2018/06/27 13:03] (current) root |
||
|---|---|---|---|
| Line 38: | Line 38: | ||
| </ | </ | ||
| + | ==== Set Reporter ID to be a value from a custom field called User ID ==== | ||
| + | <code java> | ||
| + | import com.atlassian.jira.issue.CustomFieldManager | ||
| + | import com.atlassian.jira.issue.fields.CustomField | ||
| + | import com.atlassian.jira.component.ComponentAccessor | ||
| + | |||
| + | CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() | ||
| + | CustomField cfUID = customFieldManager.getCustomFieldObjectByName(" | ||
| + | def cfUIDvalue = issue.getCustomFieldValue(cfUID) | ||
| + | |||
| + | issue.reporterId=cfUIDvalue | ||
| + | </ | ||
| + | |||
| + | ==== Add users to watch list on create or transition ==== | ||
| + | |||
| + | If you're using this code on issue creation, make sure the script is after the " | ||
| + | |||
| + | <code java> | ||
| + | import com.atlassian.jira.component.ComponentAccessor | ||
| + | def watcherManager = ComponentAccessor.getWatcherManager() | ||
| + | def userManager = ComponentAccessor.getUserManager() | ||
| + | def watchUsers = {usernames -> | ||
| + | usernames.each { | ||
| + | def user = userManager.getUserByKey(it.toString()) | ||
| + | if (user) { | ||
| + | watcherManager.startWatching(user, | ||
| + | } | ||
| + | | ||
| + | } | ||
| + | } | ||
| + | def users = [" | ||
| + | if (issue.projectObject.key == ' | ||
| + | watchUsers(users) | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === Set custom text field value in field Approval Status with date/time & currentUser on POST transition === | ||
| + | |||
| + | <code java> | ||
| + | import com.atlassian.jira.component.ComponentAccessor | ||
| + | import com.atlassian.jira.issue.fields.CustomField | ||
| + | //Define cfm | ||
| + | def cfm = ComponentAccessor.getCustomFieldManager() | ||
| + | //Set custom text field for Text field called " | ||
| + | def cfApprovalStatus = cfm.getCustomFieldObjectByName(" | ||
| + | def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() | ||
| + | def currentDate = new Date().format( ' | ||
| + | def statusMessage = " | ||
| + | issue.setCustomFieldValue(cfApprovalStatus, | ||
| + | </ | ||
| + | |||
| + | === Set " | ||
| + | <code java> | ||
| + | import com.atlassian.jira.component.ComponentAccessor | ||
| + | import com.atlassian.jira.issue.fields.CustomField | ||
| + | //define cfm | ||
| + | def cfm = ComponentAccessor.getCustomFieldManager() | ||
| + | |||
| + | // get value for " | ||
| + | def cfApprovalStatus = cfm.getCustomFieldObjectByName(" | ||
| + | def SelApp = cfm.getCustomFieldObjectByName(" | ||
| + | def SelAppValue = issue.getCustomFieldValue(SelApp) | ||
| + | //If there is a value in the Selected Approver, set value in Approval Status | ||
| + | if (SelAppValue){ | ||
| + | issue.setCustomFieldValue(cfApprovalStatus," | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === Additional actions performed on Issue Clone post function === | ||
| + | |||
| + | <code java> | ||
| + | def cfD = customFieldManager.getCustomFieldObjects(issue).find {it.name == ' | ||
| + | def cfS = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Start Date'} | ||
| + | def cfE = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'End Date'} | ||
| + | |||
| + | issue.setCustomFieldValue(cfD, | ||
| + | issue.setCustomFieldValue(cfS, | ||
| + | issue.setCustomFieldValue(cfE, | ||
| + | |||
| + | issue.summary = ' | ||
| + | |||
| + | import com.onresolve.scriptrunner.runner.util.UserMessageUtil | ||
| + | |||
| + | UserMessageUtil.success(' | ||
| + | </ | ||
| + | |||
| + | === Update Select List (Drop Down) field Status with value Waiting Approval === | ||
| + | |||
| + | <code java> | ||
| + | import com.atlassian.jira.component.ComponentAccessor | ||
| + | def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName(" | ||
| + | def cfConfig = cfSelect.getRelevantConfig(issue) | ||
| + | def value = ComponentAccessor.optionsManager.getOptions(cfConfig)? | ||
| + | it.toString() == ' | ||
| + | } | ||
| + | issue.setCustomFieldValue(cfSelect, | ||
| + | </ | ||