The need to create Requests in different Service Desks has grown over the last few months. I used to follow these steps:
1. Add a script to a workflow post-function that creates the ticket in the other service desk (using "issueService")
2. Add another script to the workflow on the other Service Desk to add a "Customer Request Type" (using issue.setCustomFieldValue([Customer Request Type Field], [Customer Request Type Id]), where the Id looked something like this: key/kjjfsd03kjs03jklj1293ckjf)
The "problem" is that I don't want to do step 2 for EVERY SINGLE request that I create in a different Service Desk. I would rather include the "Customer Request Type" in step 1. This will eliminate the need to always build in "defaults" or logic that adds the correct Customer Request Type.
Here is my attempt at including the "Customer Request Type" with the issueInputParameters (removed code that probably isn't relevant):
def IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.addCustomFieldValue(customer_request_type.getId(), customer_request_type_key.toString())
def validationResult = issueService.validateCreate(loggedInUser, issueInputParameters)
def issueResult = issueService.create(loggedInUser, validationResult)
I have tried a few different customer_request_type_key values:
The first one works every single time I use it with issue.setCustomFieldValue(), which almost always occurs on the create transition.
I have also attempted to do a issueService.validateUpdate() and issueService.update(). But I get the same result...still an empty Customer Request Type. I suspect the problem comes from IssueInputParameters. I couldn't find any other method besides addCustomFieldValue that made sense to use.
I also attempted to just do issueResult.getIssue().setCustomFieldValue() in the same script as above, but it never is successful.
Any help/tips would be greatly appreciated.
For those interested, this is what I eventually did:
The cf_Service is a separate script that makes it slightly easier to grab the objects and values of a specific custom field.
The nice thing about doing it this way is that I can send that Customer Request Key anywhere and in any way, and it'll update the Customer Request Type of the issue. This solved my problem which was constantly needing to write a script for the sending Service Desk AND the receiving Service Desk EVERY SINGLE time I was creating a ticket in another Service Desk.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
GroovyShell shell = new GroovyShell()
def cf_Service = shell.parse(new File('./scripts/jira_scripts/Issue_Services/cf_Service.groovy'))
//User that will update the issue.
def jiraAdminUser = ComponentAccessor.getUserManager().getUserByName('jira-localadmin')
//Get Customer Request Type and Customer Request Key objects.
def requestType = cf_Service.getCF_getValue(issue, "Customer Request Type")
def crtKey = cf_Service.getCF_getValue(issue, "Customer Request Key")
//Check if Customer Request Key has a value
if (crtKey.value) {
//Converts Customer Request Key (which is a string) to an actual Request Type object
def newRequestKey = requestType.cf.getCustomFieldType().getSingularObjectFromString(crtKey.value)
def modifiedValue = new ModifiedValue(null, newRequestKey)
//Update the value of the request type on the ticket
requestType.cf.updateValue(null, issue, modifiedValue, new DefaultIssueChangeHolder())
def deleteKey = new ModifiedValue(null, "")
//Delete the Customer Request Key value on the ticket
crtKey.cf.updateValue(null, issue, deleteKey, new DefaultIssueChangeHolder())
//Actually update the ticket
ComponentAccessor.issueManager.updateIssue(jiraAdminUser, issue, EventDispatchOption.ISSUE_UPDATED, false /*sendMail*/)
}
Have you tried passing the request type object itself?
You can figure out how to get the object by referring to this script: Get the Request Type Name in an Issue Event Listener
Cheers,
Helmy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, but the IssueInputParameters.addCustomFieldValue(Long, String) requires that I provide the customFieldID, and a String value.
I followed the script you provided and get this from the "requestType" variable (log.warn(request type object - request type class)): requestType: com.atlassian.servicedesk.internal.feature.customer.request.requesttype.CachedImmutableRequestTypeImpl@20b64a71 - class com.atlassian.servicedesk.internal.feature.customer.request.requesttype.CachedImmutableRequestTypeImpl
If I spit out the object as a string all I get is "com.atlassian.servicedesk.internal.feature.customer.request.requesttype.CachedImmutableRequestTypeImpl@20b64a71" which doesn't work. Thoughts?
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.