Use the JEMH Script Postfunction
- 1 Summary
- 1.1 Edit time screenshot
- 1.2 Preview
- 1.3 Example code
- 1.4 Context
Summary
since JEMH 4.2.12
Post-Functions are used as part of a Jira project workflow. When transitioning from one workflow step to another (e.g. "Open" to "In Progress"), Post Functions can be added to execute within the transition.
The JEMH Script Postfunction allows some issue operations to be made using available script engines (Nashhorn, Groovy).
Edit time screenshot
Preview
The preview feature allows the script to be evaluated in the context of the issue you define. Debug (via print(“nnn”)) output will be shown on screen and will also be logged in the JEMH log (see Enabling JEMH logging ).
Example code
Engine | Goal | Code Snippet |
---|---|---|
Oracle Nashorn : ECMAScript : ECMA - 262 Edition 5.1 | Append “[UPDATED]” and the current date to an issue summary. Then set the priority of the issue to the highest. | print('issue: '+issue.getKey());
print('issueSummary: '+issue.getSummary());
var updatedSummary=issue.getSummary()+" [UPDATED] "+new Date().toString();
print('updating issue to: '+updatedSummary);
issue.setSummary(updatedSummary);
issue.setPriorityId(1); |
Oracle Nashorn : ECMAScript : ECMA - 262 Edition 5.1 | Add all the pinned comments of an issue to the issues description. | adminUser = userManager.getUserByName("admin");
if (adminUser !== null) {
pinnedComments = commentManager.getPinnedComments(issue, adminUser);
var description = "";
for (i = 0; i < pinnedComments.length; i++) {
description = description + pinnedComments[i].getComment().getBody() + "\n";
}
issue.setDescription(description);
} |
Oracle Nashorn : ECMAScript : ECMA - 262 Edition 5.1 | Set an assignee of an issue, if the user “user1” exists. When the user doesn’t exist, sets the assignee of the issue as admin. | user = userManager.getUserByName("user1");
if (user !== null) {
issue.setAssignee(user);
} else {
adminUser = userManager.getUserByName("admin");
issue.setAssignee(adminUser);
} |
Oracle Nashorn : ECMAScript : ECMA - 262 Edition 5.1 | Gather a value from a Text Custom Field and then add this value as a Comment on the issue using the Reporter user. |
Context
The classes available in the context are limited. Log a Support ticket if you need to do something else:
Key | Class | Value (text) |
---|---|---|
Integer | class java.lang.Integer | |
Long | class java.lang.Long | |
applicationProperties | com.atlassian.jira.config.properties.ApplicationPropertiesImpl | com.atlassian.jira.config.properties.ApplicationPropertiesImpl |
baseurl | ||
commentManager | com.atlassian.jira.issue.comments.DefaultCommentManager | |
customFieldManager | com.atlassian.jira.issue.managers.CachingCustomFieldManager | |
dateFormatter | com.atlassian.jira.web.util.OutlookDate | |
groupManager | com.javahollic.jira.emh.service.security.SafeGroupManager | |
issueLinkService | com.atlassian.jira.bc.issue.link.DefaultIssueLinkService | |
issueManager | com.atlassian.jira.issue.managers.RequestCachingIssueManager | com.atlassian.jira.issue.managers.RequestCachingIssueManager |
jemhDateUtils | com.javahollic.jira.emh.velocity.JemhDateUtils | |
jemhVersion | 4.2.12 | |
jqlQueryBuilder | com.atlassian.jira.jql.builder.JqlQueryBuilder | |
log | org.apache.log4j.Logger | |
numberTool | com.atlassian.jira.util.velocity.NumberTool | |
objectFacade | com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade | com.riadalabs.jira.plugins.insight.channel.external.api.facade.impl.ObjectFacadeImpl |
objectSchemaFacade | com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectSchemaFacade | com.riadalabs.jira.plugins.insight.channel.external.api.facade.impl.ObjectSchemaFacadeImpl |
objectTypeAttributeFacade | com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade | com.riadalabs.jira.plugins.insight.channel.external.api.facade.impl.ObjectTypeAttributeFacadeImpl |
objectTypeFacade | com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeFacade | com.riadalabs.jira.plugins.insight.channel.external.api.facade.impl.ObjectTypeFacadeImpl |
pagerFilter | com.atlassian.jira.web.bean.PagerFilter | |
projectManager | com.atlassian.jira.project.CachingProjectManager | |
projectRoleManager | com.atlassian.jira.security.roles.DefaultProjectRoleManager | |
remoteIssueLinkService | com.atlassian.jira.bc.issue.link.DefaultRemoteIssueLinkService | |
searchService | com.atlassian.jira.bc.issue.search.DefaultSearchService | |
textUtils | com.javahollic.jira.emh.service.security.SafeTextUtils | |
userManager | com.atlassian.jira.user.util.DefaultUserManager | |
userPropertyManager | com.atlassian.jira.user.DefaultUserPropertyManager | |
userSearchService | com.atlassian.jira.bc.user.search.DefaultUserPickerSearchService | |
watcherManager | com.atlassian.jira.issue.watchers.DefaultWatcherManager |