Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Clone item if request type matches

Ana Luiza Chagas
Contributor
May 22, 2024

Hi Team!

My team and I are using a post function scriptrunner for jira cloud to clone items for other projects.

We are faced with a scenario in which cloning of items should only be done if the type of request (customfield_10010) is the same or different from that informed.

I've already tested both ways within the post function as shown in the image below, but without success.

condition.PNG

This happens even when opening tickets corresponding to the type of request informed in the ID.

Has anyone seen anything like this? Can you help me?

Thanks!

2 comments

Sean Chua _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 23, 2024

Hey @Ana Luiza Chagas ,

It looks like you are trying to ensure the condition is set to JSM's request type. Have you tried using it with the name? 

eg: 

issue.customfield_10010?.requestType?.name == 'Create Ticket'
That seems to work for me :) 
Hope that helps,
Sean
Ana Luiza Chagas
Contributor
May 23, 2024

Hi @Sean Chua _Adaptavist_ 

I tested the solution you suggested in your comment, but in all cases (even with the ticket being the same type of request that I indicated by name) the log reports that there are no matches and therefore the flow does not work as expected.

I followed this: issue.customfield_10010?.requestType?.name == 'New user'

Thanks

Sean Chua _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 23, 2024

Hi @Ana Luiza Chagas ,

Did a check with my Jira Cloud instance to test the Built-in Clone Issue again. Try using this:

issue.fields.customfield_10010.requestType.name == "New user"

I set mine up as a Post Function when I transition to "Done". It successfully cloned general details within the same project, and then tried it to another JSM project - both works. I would assume that it should work with any other project as well to clone the general default field details. If you need to fill up fields and/or other specific details, you can add the code at the bottom console for "Additional Code".

Here is the workflow set up:

image.png

And this is the ticket which was cloned/created in the other project and linked back to original ticket:image.png

Hope that helps

Like Ana Luiza Chagas likes this
Ana Luiza Chagas
Contributor
May 27, 2024

Hi @Sean Chua _Adaptavist_ 

Thank you very much for the solution. Now the function worked in my project and worked as expected!

One question, if there are more scenarios like this, could you indicate how in this example below? 

issue.fields.customfield_10010.requestType.name == ("New user", "New account")

Thanks!

imadero May 28, 2024

The solution will be 

["New user", "New account"].includes(issue.fields.customfield_10010.requestType.name)

 

Thanks, Ivan.

Like Ana Luiza Chagas likes this
Ana Luiza Chagas
Contributor
June 17, 2024

Hi @imadero, I apologize for the delay!

I tested the example you mentioned to handle two types of requests or the same time, but I got the following error:

2024-06-17 19:48:55.087 ERROR - No signature of method: java.util.ArrayList.includes() is applicable for argument types: (String) values: [New user]
Possible solutions: indexed() on line 1
2024-06-17 19:48:55.104 ERROR - Class: com.adaptavist.sr.cloud.workflow.CloneIssue, Config: [className:com.adaptavist.sr.cloud.workflow.CloneIssue, uuid:18dbe964-2691-4766-b16e-e63ee305b6a3, enabled:true, executionUser:ADD_ON, condition:["New user", "New account"].includes(issue.fields.customfield_10010.requestType.name), description:Teste, issueTypeId:, linkDirection:Inward, linkTypeId:10001, projectId:10012, additionalCode:issueInput.fields.assignee = [id:'712020:b1024cd5-3f4d-4c02-b493-91cad3ab03df'] as Map
issueInput.fields.reporter = [id:'63b471be741248746bf78990'] as Map, accountId:63c01e652341bff4fff6d85b]

Have you ever seen something similar?

Thanks for the help!

imadero June 19, 2024

Hi.

I thought this condition should be a jira expression but looks it's java.

issue.fields.customfield_10010.requestType.name in ["New user", "New account"]

or another option could be 

issue.fields.customfield_10010.requestType.name == 'New user'  || issue.fields.customfield_10010.requestType.name == 'New account'

 

Thanks, Ivan.

Laura Jimenez Valencia October 15, 2024

Hi @Sean Chua _Adaptavist_ ,

I have the same problem, and I test your solution and doesn't work. I don't know why. I add screenshots of my test. Can you help me?

 

Snipaste_2024-10-15_10-40-25.pngSnipaste_2024-10-15_10-41-16.pngSnipaste_2024-10-15_10-41-48.pngSnipaste_2024-10-15_10-43-20.png

 

Thanks!

Sean Chua _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 20, 2024

hey @Laura Jimenez Valencia ,

I just did another test, incase there was any changes, and it looks like it still works, when I set the condition with:

issue.fields.customfield_10010.requestType.name == "For Demo General"

I don't think it is a case-sensitive issue, but you could try something like:

issue.fields.customfield_10010.requestType.name.equalsIgnoreCase("for demo general")

Anyway, I created the ticket directly from portal and had the post-function run:

image.png

image.png


My views:
Eg1: ScriptRunner for Jira Cloud's workflow page:

image.png

Eg2: Workflow (edit) page, I believe you are trying to do a post-function at portal ticket creation/submit:

image.png

 

If you've tried it all, well, the only other recommendation I have left would be to create a Support Ticket with us and let our support engineers give it a shot.

 

Sean Chua _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 22, 2024

Hey @Laura Jimenez Valencia , I saw your support ticket with ScriptRunner. Glad to managed to get it to work.

For sharing with everyone. It didn't occur to me to check against whether the issue type is correct/valid in the project of cloning - simple things does get overlooked sometimes.

Here are some additional checks for future references:

1. Check if the issue type selected is correct/valid in the projects.

2. Apply the right Conditional Expression to validate and prevent potential "infinite loops".

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events