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
Custom Fields have ID’s eg customfield_12345, find these on the Jira Custom field page, hover over the ‘Edit’ link and check bottom of browser to locate.
Goal | Code Snippet |
---|---|
Set a custom field value | cfObj = customFieldManager.getCustomFieldObject('customfield_10114');
issue.setCustomFieldValue(cfObj, "a new value"); |
Making decisions based on Customer Request Type | var custRequestType = customFieldManager.getCustomFieldObject('customfield_10203');
var issueVal = issue.getCustomFieldValue(custRequestType);
if (issueVal!==null && issueVal.toString().toLowerCase().equals("itsm/getithelp") ) {
print("requestTypeVal: "+issueVal);
cfObj = customFieldManager.getCustomFieldObject('customfield_10114');
issue.setCustomFieldValue(cfObj, "ITSM CRT set");
} |
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); |
Add all the pinned comments of an issue to the issues description. | |
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. | |
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) |
---|---|---|
issue | Issue object | |
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 |