You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
Hi
I would like to know if someone knows how to set the Customer Request Type using an scriptrunner listener.
In my case, I want to set a Customer Request Type with the same name as the Issue Type, this should work on different projects which shares issue types and request types.
I've tried with this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption;
String CORRECTIVO = "Correctivo"
ApplicationUser user = ComponentAccessor.getUserManager().getUserByName("admin")
MutableIssue issue = (MutableIssue) event.issue;
log.warn("issueKey = "+ issue.key)
def cfRequestType = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Customer Request Type")[0]
String issueType = issue.getIssueType().getName();
log.warn("issueType = "+ issueType)
String requestType = "";
switch(issueType){
case "Correctivo":
requestType = CORRECTIVO;
break;
}
log.warn("requestType = "+requestType)
log.warn( cfRequestType.getCustomFieldType().getSingularObjectFromString(requestType) )
def fieldRequestType = cfRequestType.getCustomFieldType().getSingularObjectFromString(requestType)
issue.setCustomFieldValue(cfRequestType, requestType)
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
But is giving me this error:
2021-01-08 10:57:33,387 WARN [runner.ScriptBindingsManager]: issueKey = CPAMSSAP-133 2021-01-08 10:57:33,387 WARN [runner.ScriptBindingsManager]: issueType = Correctivo 2021-01-08 10:57:33,387 WARN [runner.ScriptBindingsManager]: requestType = Correctivo 2021-01-08 10:57:33,387 WARN [runner.ScriptBindingsManager]: 2021-01-08 10:57:33,389 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2021-01-08 10:57:33,389 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null java.lang.ClassCastException: java.lang.String cannot be cast to com.atlassian.servicedesk.internal.customfields.origin.VpOrigin at com.atlassian.servicedesk.internal.customfields.origin.VpOriginCFType.getDbValueFromObject(VpOriginCFType.java:82) at com.atlassian.jira.issue.customfields.impl.AbstractSingleFieldType.createValue(AbstractSingleFieldType.java:143) at com.atlassian.jira.issue.fields.ImmutableCustomField.createValue(ImmutableCustomField.java:693) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:410) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:396) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateFieldValues(DefaultIssueManager.java:728) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:681) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:667) at com.atlassian.jira.issue.managers.RequestCachingIssueManager.updateIssue(RequestCachingIssueManager.java:217) at com.atlassian.jira.issue.IssueManager$updateIssue$0.call(Unknown Source) at Script993.run(Script993.groovy:34)
Thanks in advance to everyone!
The manager’s daily activities include a list of challenges to reach high levels of efficiency for their teams. Part of these challenges is related to how to deal with the worklog systems sin...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events