Hi,
So Jonny is right saying that 'Service Desk fields can be a bit tricky' and his script is 100% correct for a single select list (as he did mention). But the Customer Request Type does not behave as a Single Select list. So ...
import com.atlassian.jira.component.ComponentAccessor // In order to find the key of it select an request type for an issue and then navigate to // http://<baseUrl>/rest/api/2/issue/<issueKey>?expand=renderedFields,editmeta // and next to the id of the Customer Request Type custom field (see below in log) you will find it def REPORT_SYSTEM_PROBLEM_KEY = "sdp/systemproblem" def customFieldManager = ComponentAccessor.getCustomFieldManager() def tgtField = customFieldManager.getCustomFieldObjectByName("Customer Request Type") // get the id of the cf in the logs in order to use it for finding the key of the Customer Request Type log.debug("Customer Request Type Custom field Id: ${tgtField.getId()}") def requestType = tgtField.getCustomFieldType().getSingularObjectFromString(REPORT_SYSTEM_PROBLEM_KEY) issue.setCustomFieldValue(tgtField, requestType)
hope that helps, Thanos
if u stumble over this...
the request type in:
issue.setCustomFieldValue(tgtField, requestType)
has to be the key NOT the id you grab from the rest api or the logs.
only the according entry to:
sdp/systemproblem
Btw, it seems that you do not have to be successful in setting a correct type.
After setCustomFiel..the request will show up in the customer portal, even if the type shows NULL in the issue itself..
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.
EDIT: See Thanos's answer, above. This is not quite right.
Service Desk fields can be a bit tricky, but I have seen examples of setting it via Behaviours (e.g. https://answers.atlassian.com/questions/15836926).
If it behaves like other fields in the context of Post Functions, then you could do something like:
import com.atlassian.jira.component.ComponentAccessor def customFieldManager = ComponentAccessor.customFieldManager def crtField = customFieldManager.getCustomFieldObjects(issue).find{it.name == "Customer Request Type"} issue.setCustomFieldValue(crtField, "Desired Request Type")
It may be that the Customer Request Type behaves like a select list, in which case, you may need to bring in the Options manager.
import com.atlassian.jira.component.ComponentAccessor def customFieldManager = ComponentAccessor.customFieldManager def optionsManager = ComponentAccessor.optionsManager def crtField = customFieldManager.getCustomFieldObjects(issue).find{it.name == "Customer Request Type"} def fieldConfig = crtField.getRelevantConfig(issue) def options = optionsManager.getOptions(fieldConfig) def optionToPick = options.find{it.value == "Desired value"} issue.setCustomFieldValue(crtField, optionToPick)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello. I tried to use that "select list options" code snippet with Customer Request Type field but it does not work.
Here are some ways to retrieve "project/UUID" expected values for this custom field:
- inspect jira page DOM to look for select option
- query database thanks to SQL query available at https://community.atlassian.com/t5/Jira-Service-Desk-questions/Re-set-customer-request-type-with-script-runner/qaq-p/120737/comment-id/1213#M1213
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Another way (using an internal REST API endpoint) is explained in: https://community.atlassian.com/t5/Jira-questions/Setting-the-Requst-Type-of-a-newly-created-Issue-via-remote-API/qaq-p/1118219#U1122068
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Set Customer request field on create issue:
This is how I did it.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
def logs = Logger.getLogger("com.acme.workflows")
logs.warn("Workflow function running...")
//set Customer request type
def cfCustomerRequestType = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Customer Request Type").first();
final String SERVICE_REQUEST = "bsdr/5dd969ce-dcf6-46cd-9900-814174943441"
def customerRequest = cfCustomerRequestType.getCustomFieldType().getSingularObjectFromString(SERVICE_REQUEST)
logs.warn("customerRequest: " + customerRequest)
IssueManager issueManager = ComponentAccessor.getIssueManager()
MutableIssue issueToUpdate = issueManager.getIssueObject(issue.getId()) as MutableIssue
issueToUpdate.setCustomFieldValue(cfCustomerRequestType, customerRequest);
issueManager.updateIssue(issue.getReporterUser(), issueToUpdate, EventDispatchOption.ISSUE_UPDATED, false);
In the variable, SERVICE_REQUEST set the UUID of your desired Customer Request type that you get from the database and it will work.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you, works like a charm
Query to get UUID of SERVICE_REQUEST
select stringvalue
from customfieldvalue
where issue=(
select id from jiraissue where issuenum=123 and project=(select id from project where pkey='JRA')
)
and customfield=10909;
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.