Hi!
I'm new here and also a new user of the Adaptavist Scriptrunner.
I'm trying to setup our create issue screen that when the 'Project Group' is Emergency, ticket priority will be set to High when the ticket gets created (Priority is not in the list that user needs to fill out).
I researched all over and came up with this. I am not sure where the problem may be because I'm not receiving any errors. **sorry if it looks bad, it's my first time to try this**
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.PrioritySystemField
def ProjectGroup = getFieldById("customfield_14701")
def Priority = getFieldById("Priority")
if (ProjectGroup.getValue() == "Emergency") {
Priority.setFormValue("High")
}
else {
Priority.setFormValue("Medium")
}
I hope someone can help me. Thank you :)
Hi @Sha A.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issue = issue as MutableIssue
IssueManager issueManager = ComponentAccessor.getIssueManager()
def constantsManager = ComponentAccessor.getConstantsManager()
def projectGroupField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Your Field")
def projectGroup = issue.getCustomFieldValue(projectGroupField)
Priority priority = constantsManager.getPriorities().find{it.name =="High}
if(projectGroup == "Emergency"){
issue.setPriorityId(priority.id)
}
issueManager.updateIssue(user,issue,EventDispatchOption.DO_NOT_DISPATCH,false)
Just add the ifs/else that you need, but that should work
Hope that helps you.
Hi @Gustavo Félix ,
Thank you for you help on this. I really appreciate it.
Unfortunately I am getting an error without any details.
Correct me please if I am wrong this is what I did:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issue = issue as MutableIssue
IssueManager issueManager = ComponentAccessor.getIssueManager()
def constantsManager = ComponentAccessor.getConstantsManager()
def projectGroupField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Project Group")
def projectGroup = issue.getCustomFieldValue(projectGroupField)
Priority priority = constantsManager.getPriorities().find{it.name =="High}
if(projectGroup == "Emergency"){
issue.setPriorityId(priority.id)
}
issueManager.updateIssue(user,issue,EventDispatchOption.DO_NOT_DISPATCH,false)
Line with Priority priority gives a red x error but no message.
Thank you again. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Sha A. At the end of High you need to add the " .
I saw that I missed it on my example.
Priority priority = constantsManager.getPriorities().find{it.name =="High"}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Gustavo Félix ,
Thanks for confirming. I tried that and added the " after High but the red x without a message still shows up for the line.
Thank you. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you still have the error , can you add your code so I can see it ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issue = issue as MutableIssue
IssueManager issueManager = ComponentAccessor.getIssueManager()
def constantsManager = ComponentAccessor.getConstantsManager()
def projectGroupField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Project Group")
def projectGroup = issue.getCustomFieldValue(projectGroupField)
Priority priority = constantsManager.getPriorities().find{it.name =="High"}
if(projectGroup == "Emergency"){
issue.setPriorityId(priority.id)
}
else {
Priority.setFormValue("Medium")
}
issueManager.updateIssue(user,issue,EventDispatchOption.DO_NOT_DISPATCH,false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you have the import related to Priority ?
In my test is :
import com.atlassian.jira.issue.priority.Priority
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, another question.
Are you using this code as a postfunction or a behaviour?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am using behaviors. I'm not really sure how to configure it via postfunction. I am not able to figure out which postfunction would work the way we need it to.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think it fits better with a postfunction.
You can follow this.
https://scriptrunner.adaptavist.com/latest/jira/tutorials/scripted-post-functions-tutorial.html
The transition that it mentions, is the create transition.
The post function that you are going to add is a "Script post Function" -> Custom script post function.
You can paste the code that I put you, and it should work. Just add the other ifs/else that you need for the other priorities.
Let me know if you have any problems.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.