I am trying to implement a solution using Adaptavista ScriptRunner and am running into some difficulties making the code work as expected.
System: JIRA 7.11.1
JIRA Service Desk
Scenario/ Use Case: When creating a new issue from the JIRA channel (not the service desk Customer Portal channel) on the create screen I would like to be able to edit the "Customer Request Type" field using ScriptRunner to select a specific "Customer Request Type" when the issue creator selects a specific "Issue Type". If customer selects issue type A, then Customer Request Type A is also selected. In addition I would like to always hide the "Customer Request Type" field on the create issue screen so that users cannot change it.
I am running into difficulty as the "Customer Request Type" doesn't seem to conform to any of the field types I have previously used ScriptRunner on (Select List, Multi Select List, Radio Button). I am sure this something that can be handled in 6 to 8 lines of code, but I am not having any luck at all with getting the expected results.
Any help or guidance you can provide is greatly appreciated.
I was able to use the Initialiser to hide the field "Customer Request Type" for the create screen, however I am not able to figure out how to set the field value for the Customer Request field. Any help on what I am doing wrong would help. The error I am getting is on the very last line of this code (see code block for complete example) : issue.setCustomFieldValue(tgtField, requestType)
def fieldToHide = getFieldByName("Customer Request Type")
def IssueType = getFieldByName("CF Request")
def optionValue = IssueType.getValue().toString()
fieldToHide.setHidden(true)
if (optionValue == 'Non-template') {
fieldToHide.setHidden(false)
}
import com.atlassian.jira.component.ComponentAccessor
def QuantumRequest = "key/444099ab-e1bd-4a9d-8f09-11c93f104d15"
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def tgtField = customFieldManager.getCustomFieldObjectByName("Customer Request Type")
log.debug("Customer Request Type Custom field Id: ${tgtField.getId()}")
def requestType = tgtField.getCustomFieldType().getSingularObjectFromString(CFRequest)
issue.setCustomFieldValue(tgtField, requestType)
Trying to help myself out as bit as this is a pressing issue I need solved. Looks like Customer Request Type doesn't conform to other field types, so I have to use a different methodology to reference that field:
From the Scrip Console:
import com.atlassian.jira.component.ComponentAccessor
def issue = ComponentAccessor.issueManager.getIssueByCurrentKey("KEY-###")
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Customer Request Type")
issue.getCustomFieldValue(cf)
From there the results provide the field name:
key/444099ab-e1bd-4a9d-8f09-11c93f104d15
I found some more details here to assist with the Customer Request Type field
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.