This script can be used either on Script Field Processor (Use Script Field Processor ) which means it is triggered depending on your Directive Processing Behaviour as set mentioned here https://thepluginpeople.atlassian.net/wiki/spaces/JEMH/pages/227115013/Use+Script+Field+Processor#Enable-Directives.
If required in a specific Project Mapping the Script Rule (/wiki/spaces/JEMH/pages/223739905) Please note however the limitation for the Script Rule is that it is processed only during issue creation. This is because it is a Mapping Rule this means it only applies during creation.
We will making use of directives via the resultMap.put(<directive>, <param)
more information on directives here Use Directive Sets. Supported fields for directives here: Supported fields for use with Directives.
You will need this Project ID to find the Project Object in the script. This can be found via Project Settings > Details in the URL bar of your browser it will be listed as a query parameter as shown below:
You can find this via Jira Administration > Security > Project Roles then edit the desired role.
Similarly to Project ID you will find the Project Role ID in the URL bar as a query parameter:
//Go through each address in ccAddresses for(var i = 0;i < ccAddresses.length; i++) { //determine is email address is a jira user. var emailAddress = ccAddresses[i].getAddress(); print("[" + emailAddress + "] detected email address"); var jiraUser = jemhUtils.getUserByEmail(emailAddress); if(jiraUser == null) { print("["+ emailAddress + "] was not an email address related to a Jira User"); } else { print("processing email and attempting to find related users"); //get current project use your own project id here. var project = jemhUtils.getProjectContext(10300).getProjectObject(); print("["+project.getName()+"] Project Found"); //get required project role use your own project id here. var projectRole = projectRoleManager.getProjectRole(10101); print("["+projectRole.getName()+"] Project Role Found"); //check if the user is in the role var isInProjectRole = projectRoleManager.isUserInProjectRole(jiraUser, projectRole, project); print("Is user in the Project Role"+"["+projectRole.getName()+"] returned ["+isServiceDeskTeamRole+"]"); //user is in the role then add them to watcher if(isInProjectRole) { print("["+ emailAddress + "] will be added to watchers"); resultMap.put("watchers", jiraUser.getUsername()); } //Any other Jira user is added to request participants else { print("["+ emailAddress + "] will be added to request participants"); resultMap.put("Request participants", jiraUser.getUsername()); } } } |
The result of this example script is that if a non-jira user is found then it will be logged in the report. However if a
Jira user is found then:
If the user is not in the Service Desk Team Role then they will be added to request participants
If the user is Service Desk Team Role then they will be added to watchers