Hi team
I'm trying to write a script on condition inside a scriptrunner post function for Jira Cloud that validates that the request type is the same as the name or ID entered.
I researched this topic but found solutions only for Jira Server.
Has anyone seen something similar for Jira Cloud?
Thank you for your help!
Done, @Ana Luiza Chagas 😎
https://docs.adaptavist.com/sr4jc/latest/features/workflow-extensions/post-functions/built-in-post-functions is a good place to start for more info about Jira ScriptRunner for Cloud. But let me ask for some details
1. Which post function do you want to use? A built-in one or a completely custom one?
2 . Request type I understand, but it's not clear to me what you mean by "name or ID". Please could you add some more info about that
Hello @Matt Doar _Adaptavist_
1. My question would be about a condition within the scriptrunner post function, being the first topic in this document: https://docs.adaptavist.com/sr4jc/latest/features/workflow-extensions/post-functions/fields
2. I would like to know if I need to enter the name or ID of the request types in the customfield_10010 field in Jira Service Management.
I tried something like: (map(issue.fields.requesttype)?.name == "Password update"
But I was unsuccessful
Have you ever seen something like this?
Thanks for the help!
Hi Ana,
There's a couple of questions here.
Are you sure you mean a post-function and not a condition? If so, then I assume your "condition" is a decision point for the following code that will update something. Like "If request-type = 4, then change field X to Y, else copy summary to field Z"
I am not sure what you mean by "the request type is the same as the name or ID entered". The issue you are running the post-function for will have the request type that was entered when the customer created the request, so I'm not sure what you are trying to compare it to.
But to get you started, the request type for an issue shows up as a custom field.
If you go to the Scriptrunner console and run the following code (this is one of the built-in example scripts), you will get a view of all the fields on the issue HELP-1.
def issueKey = 'HELP-1'
def result = get('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status == 200){
return result.body.fields
} else {
return "Failed to find issue: Status: ${result.status} ${result.body}"
}
"customfield_10010": { "_links": { "jiraRest": "https://nbrough-adaptavist-dev.atlassian.net/rest/api/2/issue/10001", "web": "https://nbrough-adaptavist-dev.atlassian.net/servicedesk/customer/portal/1/HELP-1", "self": "https://nbrough-adaptavist-dev.atlassian.net/rest/servicedeskapi/request/10001", "agent": "https://nbrough-adaptavist-dev.atlassian.net/browse/HELP-1" }, "requestType": { "_expands": [ "field" ], "id": "1", "_links": { "self": "https://nbrough-adaptavist-dev.atlassian.net/rest/servicedeskapi/servicedesk/1/requesttype/1" },
....
There's loads more content for this - I don't know which bit you are looking for
So you can get the request type (and other things about the request) by reading for customfield_10010
Hi @Nic Brough -Adaptavist-
The Script would be to check the content of the custom field customfield_10010
Ex: I have a request type called “Password Update” in Jira Service Management.
I would like the script to confirm whether the created item has the "Password Update" request type and if so, it continues the flow.
I tried something like: (map(issue.fields.requesttype)?.name == "Password update" but I was unsuccessful
Have you ever seen something like this?
Thanks for the help!
You can't stop the transition during a post-function, as post-functions are executed at the end of the transition process and are part of it.
Hi @Nic Brough -Adaptavist-
I'm trying to make a post function at the end of the create an item event to clone this item to another project. Therefore, the condition would be important because if the item presents a certain request type (customfield_10010), the cloning condition would be false, causing the item to only be cloned in some cases.
As in this example condition that the item is only cloned if its type is equal to "Bug"
Ok, thanks for clarifying all of that!
so I need to talk to the Cloud SR developers about their wording - they should not be using "Condition" here, because it has a different meaning in Jira-speak, and it confused me when reading the question (A Jira "condition" is something that stops you using a transition, not part of a transition)
Anyway, the SR-condition here uses "expressions", and as the Request Type looks a lot like a custom field (because it is implemented as one), then you should be able to use something like
issue.customfield_10010?.value == 'P42'
That assumes the ID of the Request Type is 42 (It was 1 in the response I got in the console script I gave before). I do not think it will work with the name of the Request Type, but I have not tried it.
Hi @Nic Brough -Adaptavist-
I rescued this discussion to ask for help.
I tried implementing the post function in scriptrunner for jira cloud, using the example you mentioned last month: "issue.customfield_10010?.value == 'P42'"
In this case, replacing them with the IDs of my project's request types was unsuccessful. I tried to open a ticket of the type I provided in the ID, but it doesn't work and triggers the following message in the log:
Can you help me?
Thanks your help!