Page tree
Skip to end of metadata
Go to start of metadata
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.servicedesk.api.requesttype.RequestTypeService
import com.atlassian.servicedesk.api.request.type.CustomerRequestTypeService
import com.atlassian.servicedesk.api.user.UserFactory
import com.atlassian.servicedesk.api.util.paging.SimplePagedRequest
import com.atlassian.servicedesk.api.util.paging.PagedRequest
import com.atlassian.servicedesk.api.util.paging.PagedResponse
import com.atlassian.servicedesk.api.user.UserFactory
import com.atlassian.servicedesk.api.requesttype.RequestTypeQuery
import com.atlassian.servicedesk.api.requesttype.RequestType
import com.atlassian.servicedesk.api.user.UncheckedUser
import com.atlassian.servicedesk.api.request.type.CustomerRequestType
import com.atlassian.servicedesk.api.request.type.CustomerRequestTypeQuery
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule

@WithPlugin("com.atlassian.servicedesk")
@PluginModule
RequestTypeService requestTypeService
@PluginModule
CustomerRequestTypeService customerRequestTypeService
@PluginModule
UserFactory userFactory

def currIssue = ComponentAccessor.getIssueManager().getIssueObject("CSIT-19558")
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject(10001)
def currentUser =  ComponentAccessor.getComponent(JiraAuthenticationContext.class).getLoggedInUser()
//需要更新的请求类型名称
String requestTypeName = "Windows 补丁更新"
RequestType newRequestType
int numberOfRequestTypes = 300 //approximate amount of customer request types on your instance the more the better)
for(int limitRequest = 0;limitRequest <numberOfRequestTypes;limitRequest += 100){
    PagedRequest pagedRequest = new SimplePagedRequest(limitRequest,limitRequest+100)
    RequestTypeQuery reqTypeQuery = requestTypeService.newQueryBuilder().pagedRequest(pagedRequest).build()
    PagedResponse<RequestType> reqTypes = requestTypeService.getRequestTypes(currentUser, reqTypeQuery)
    if(reqTypes.results.find{it.getName()==requestTypeName}){
       newRequestType = reqTypes.results.find{it.getName()==requestTypeName}
       break
    }
}
CustomerRequestTypeQuery customerRequestTypeQuery = customerRequestTypeService.newQueryBuilder().requestType(newRequestType).build()
UncheckedUser uncheckedUser = userFactory.getUncheckedUser()
CustomerRequestType customerRequestType = customerRequestTypeService.getCustomerRequestType(uncheckedUser, customerRequestTypeQuery) as CustomerRequestType

currIssue.setCustomFieldValue(customField,customerRequestType)

ComponentAccessor.getIssueManager().updateIssue(currentUser, currIssue, EventDispatchOption.ISSUE_UPDATED, false)


  • No labels