This information would be useful in a scenario where you would like to create a custom field processor or project mapping rule which requires the location of an issue via JQL queryis an example script for when Profile’s Script Field Processor or Project Mapping: Script Rule is required to detect whether an issue can be located via JQL Query.
Example
The following ECMAScript (JavaScript) code will run a JQL query to find an issue. The key of the first issue found in the results is set as a value for "issueKey" in the resultMap object. This "issueKey" directive would then ultimately direct JEMH to comment on the existing issue with the processed email. Note that this behaviour is just an example - you could do anything with the returned issue(s).
The below example would match against an issue that has all the following values:
Field A | Field B | Field C |
---|---|---|
apple | blueberry | carrot |
Since JEMH 3.3.21 we lock down access to arbitrary classes in the script context, they cannot be accessed using historic methods:
Code Block |
---|
var filter = PagerFilter.static.getUnlimitedFilter();
var builder = JqlQueryBuilder.static.newBuilder(); |
but need to be gained through fully specified class names:
Code Block |
---|
var filter = Java.type("com.atlassian.jira.web.bean.PagerFilter").getUnlimitedFilter();
var builder = Java.type("com.atlassian.jira.jql.builder.JqlQueryBuilder").newBuilder(); |
These specific classes were not initially added, are available since JEMH 3.3.38
Info | ||
---|---|---|
Due to issues highlighted on the following page,https://thepluginpeople.atlassian.net/wiki/spaces/JEMH/pages/3974856709/Using+Java+17#Classnotfound-exception-when-using-%E2%80%9Cjava.type%E2%80%9D. It means that if you are using Java 17 with Nashorn installed within
|
Code Block | ||
---|---|---|
| ||
//get the user to run the JQL query as var user = userManager.getUserByName("admin"); //note the use of "static" on the below 2 lines, see the additional information below var filter = PagerFilter.staticJava.type("com.atlassian.jira.web.bean.PagerFilter").getUnlimitedFilter(); var builder = JqlQueryBuilder.staticJava.type("com.atlassian.jira.jql.builder.JqlQueryBuilder").newBuilder(); //construct the JQL query var query = builder.where().defaultAnd() .field("Field A").like("apple") .field("Field B").like("blueberry") .field("Field C").like("carrot") .buildQuery(); //get list of issues (could be empty) var results = searchService.search(user, query, filter).getIssues(); //get first issue if exists and add via issueKey directive if (results.size()>0) { var issue = results[0]; resultMap.put("issueKey",issue.getKey()); print("Found using JQL: "+issue.getKey()); } else { print("No issues match using JQL."); } | ||
Info | ||
Static class member access via ECMAScriptYou may notice in the above example that thePagerFilter and JqlQueryBuilder context objects are used a bit differently to others. They refer to the Class objects of the classes, rather than an instance of a class which is normally the case for items of the script context. The static pseudo-property is used in order to access the Java type. Then, the static methods of these two classes can be accessed. |
Related articles
Filter by label (Content by label) | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...
Page Properties | ||
---|---|---|
| ||
|