Use the JEMH Script Postfunction

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

image-20240703-131027.png

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 ).

Example code

Engine

Goal

Code Snippet

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)

Key

Class

Value (text)

Integer

java.lang.Class

class java.lang.Integer

Long

java.lang.Class

class java.lang.Long

applicationProperties

com.atlassian.jira.config.properties.ApplicationPropertiesImpl

com.atlassian.jira.config.properties.ApplicationPropertiesImpl

baseurl

java.lang.String

http://localhost:8080

commentManager

com.atlassian.jira.issue.comments.DefaultCommentManager

com.atlassian.jira.issue.comments.DefaultCommentManager

customFieldManager

com.atlassian.jira.issue.managers.CachingCustomFieldManager

com.atlassian.jira.issue.managers.CachingCustomFieldManager

dateFormatter

com.atlassian.jira.web.util.OutlookDate

com.atlassian.jira.web.util.OutlookDate

groupManager

com.javahollic.jira.emh.service.security.SafeGroupManager

com.javahollic.jira.emh.service.security.SafeGroupManager

issueLinkService

com.atlassian.jira.bc.issue.link.DefaultIssueLinkService

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

com.javahollic.jira.emh.velocity.JemhDateUtils

jemhVersion

java.lang.String

4.2.12

jqlQueryBuilder

com.atlassian.jira.jql.builder.JqlQueryBuilder

com.atlassian.jira.jql.builder.JqlQueryBuilder

log

org.apache.log4j.Logger

org.apache.log4j.Logger

numberTool

com.atlassian.jira.util.velocity.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

com.atlassian.jira.web.bean.PagerFilter

projectManager

com.atlassian.jira.project.ProjectManager

com.atlassian.jira.project.CachingProjectManager

projectRoleManager

com.atlassian.jira.security.roles.ProjectRoleManager

com.atlassian.jira.security.roles.DefaultProjectRoleManager

remoteIssueLinkService

com.atlassian.jira.bc.issue.link.RemoteIssueLinkService

com.atlassian.jira.bc.issue.link.DefaultRemoteIssueLinkService

searchService

com.atlassian.jira.bc.issue.search.SearchService

com.atlassian.jira.bc.issue.search.DefaultSearchService

textUtils

com.javahollic.jira.emh.service.security.SafeTextUtils

com.javahollic.jira.emh.service.security.SafeTextUtils

userManager

com.atlassian.jira.user.util.UserManager

com.atlassian.jira.user.util.DefaultUserManager

userPropertyManager

com.atlassian.jira.user.UserPropertyManager

com.atlassian.jira.user.DefaultUserPropertyManager

userSearchService

com.atlassian.jira.bc.user.search.UserSearchService

com.atlassian.jira.bc.user.search.DefaultUserPickerSearchService

watcherManager

com.atlassian.jira.issue.watchers.WatcherManager

com.atlassian.jira.issue.watchers.DefaultWatcherManager