Clone to a Project where the Key is passed to a Smart Value from Trigger Issue
Asked by Larry Katz:

I found something similar to this, but there was no answer in a year  
<https://community.atlassian.com/t5/Automation-questions/Create-clone-issue-when-project-name-is-smart-value-dynamic/qaq-p/1494344>  

Is there a way to Clone a ticket into a project where the target value is passed from the trigger issue and parsed in a smart value? I've attempted this and it returned an error that nothing was provided.  

The goal is:  
from Jira Service Management i'm trying to keep the current ticket where it is, but if a developer wants to move into a different backlog for a release, they would choose a "Add to Development" transition in the workflow, and the automation would pick up the change to the field "Target Issue Type"  

Per other conditions in the automation, the automation would create the clone into a project, which key is passed in from the screen the user selects from. (see screenshot)  

it's more scalable for me to add the project keys to the dropdown for the user and pass them to the automation for the smart value to render it and create the ticket into that project.  

We have 50+ projects and I don't want to make numerous if/else blocks to accomplish this.  

I've tried the smart value for the custom field {{issue."Target Project Key"}} into the project dropdown but I get an error.   

Any work around here?  

![Screen Shot 2021-04-08 at 6.59.05 PM.png](/t5/image/serverpage/image-id/138040i4D03EADD61A1E492/image-size/large?v=v2&px=999 "Screen Shot 2021-04-08 at 6.59.05 PM.png")![Screen Shot 2021-04-08 at 6.59.31 PM.png](/t5/image/serverpage/image-id/138042iEAD4F83894014EAC/image-size/large?v=v2&px=999 "Screen Shot 2021-04-08 at 6.59.31 PM.png")![Screen Shot 2021-04-08 at 7.00.30 PM.png](/t5/image/serverpage/image-id/138041i3AD77FA1FD6829B1/image-size/large?v=v2&px=999 "Screen Shot 2021-04-08 at 7.00.30 PM.png")


Answers:
author: bmccoy
body: Hi,

It looks like we only accept Project IDs, not keys. I've raised a ticket for this:

<https://codebarrel.atlassian.net/browse/AUT-2194>

As a workaround you could possibly add the project ID in the drop-down e.g. "JTP \[11094\]" and then use our String functions to pull it out:

{{issue.Target Project Key.substringBetween("\[", "\]")}}

Cheers,  
Brydie

comments: author: Larry Katz
body: Thanks I've tried a few variations of this, I just can not get this to work.  

![Screen Shot 2021-04-19 at 10.59.58 AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/139353i48CE67CA6FB13B02/image-size/large?v=v2&px=999 "Screen Shot 2021-04-19 at 10.59.58 AM.png")  

Tried:

{{issue."Target Project Key".substringBetween("\[", "\]")}}

{{issue.Target Project Key.substringBetween("\[", "\]")}}

{{issue.Target Project Key.substringBetween("(", ")")}}  
{{issue.Target Project Key.substringBetween("\*", "\*")}}  

Dropdown value as JTP (10938), JTP \[10938\], JTP \*10938\*  

nothing seems to work although from your suggestion and on   
<https://confluence.atlassian.com/automation/text-functions-993924863.html>  

This solution should work fine.  
{{issue.Target Project Key}} or {{issue."Target Project Key"}} renders fine, but using in conjunction with the substringBetween() method, it does not for some reason. Should the entire JTP (10938) value be an actual string in the custom field?   

Example "JTP (10938)" instead of JTP (10938).  

Per this:  
<https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html#substringBetween-java.lang.String-java.lang.String-java.lang.String>  

This is already coming in a string.


author: bmccoy
body: Hi Larry,

What type of field is the "Target Project Key" is it a regular select list? Looks like for select lists we need to grab the "value". I've got the following working for me:

```
{{issue.Select CF.value.substringBetween("(", ")")}}
```

Cheers,  
Brydie


author: Larry Katz
body: Thanks, this totally works for my case for now while [AUT-2194](https://codebarrel.atlassian.net/browse/AUT-2194) is being considered to accept keys. Silly me I totally forgot how select menus act in terms of the value :) Appreciate the assist!


author: Haddon Fisher
body: Hey Larry,

I was able to do this in Cloud by:

- Creating a custom field to hold my project names and keys. I used a multi-select, since I need the ability to create multiple tickets, but I tested using a single select and it works the same. My naming convention is "TEAM NAME (PROJECT KEY)"

- After my trigger and conditions, I use the "Advanced Branching" option within the "Branch" section to create a new smart value. I call it "project" and it is equal to:

*

  ```
  {{#issue.Participating Teams}}{{value.replaceall("(.*)(\()(.*)(\))","$3")}}{{/}}
  ```

* This takes each value of "Participating Teams", does a regex match to find the project key between the parenthesis, and returns it.

![Screen Shot 2022-03-07 at 10.47.34 AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/186748i68386F754D39E640/image-size/large?v=v2&px=999 "Screen Shot 2022-03-07 at 10.47.34 AM.png")

- Underneath this branch, I have a "related issues" JQL condition to make sure I don't already have a ticket created in this project, linked to this issue using the relationship I use for these, and with the same summary. It checks to make sure there is NO matches to this search:

*

  ```
  project = {{project}} and summary ~ "{{triggerIssue.summary}}"
  ```

![Screen Shot 2022-03-07 at 10.47.44 AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/186749i0C17EA7408381641/image-size/large?v=v2&px=999 "Screen Shot 2022-03-07 at 10.47.44 AM.png")

- If this condition is met, I then use a "create issue" action to make the new issue with the field values I want. In the UI dropdown I leave project set to "Same Project" but in the "More Options" expand, I add the following to the "Additional Fields" box:

*

  ```
  {

       "fields": {

            "project":{

                 "key": "{{project}}"

            }

       }

  }
  ```

![screencapture-enterprisebp-sandbox-108-atlassian-net-jira-settings-automation-2022-03-07-10_47_57.png](https://community.atlassian.com/t5/image/serverpage/image-id/186750iCB41E5ED50B53461/image-size/large?v=v2&px=999 "screencapture-enterprisebp-sandbox-108-atlassian-net-jira-settings-automation-2022-03-07-10_47_57.png")

It would be really nice to be able to just use a smart value directly though - I am not sure if that other ticket survived absorption into Atlassian, so I also put [JRACLOUD-78577](https://jira.atlassian.com/browse/JRACLOUD-78577)


author: Bill Sheboy
body: Hi [@Larry Katz](/t5/user/viewprofilepage/user-id/3460959)

One work-around for this, albeit a slower one is to use the REST API to get at the Project ID from the name:

* Once you have the project name from your custom field...
* Make a [webrequest action call](https://community.atlassian.com/t5/Jira-articles/Automation-for-Jira-Send-web-request-using-Jira-REST-API/ba-p/1443828) to the [REST API for get all projects](https://docs.atlassian.com/software/jira/docs/api/REST/1000.824.0/#api/2/project-getAllProjects)
* Parse the response using a regular expression, creating a Project Name/ID list in a created variable
* Use the Match function with the target project name on the created variable to pull the ID you need
* Clone your issue using the ID

Best regards,

Bill


author: Curt Holley
body: Interesting scenario.

Not sure it can be done as simply as you are thinking (happy and interested in being proven wrong though).

Your "Add to development" screen is kinda as complex as doing a manual cloning process, so....

**Best I can think of is:**

Replace it with "manual trigger" based automation. This would really simple automation done per Project.

Pros: Easy to copy, edit project and create the next one. *So not as hard as a 50 plus if else statement and easy enough to keep adding more as more projects are created*

Cons: This would mean 50 plus manual trigger automation rules for people to scroll through. *But if they all started with the relevant Project key, then..... Maybe it could work?*

It would also be a change in current (I presume) procedure.

It still requires some manual effort (arguably not any more than the "Add to development" screen though) and refactoring to keep in sync with new projects, archived/trashed projects. *Again, similar to the maintenance effort of the "Add to development" screen.*

Not sure how helpful I've been? ??

comments: author: Laura Campbell _Seibert Media_
body: Don't know if you absolutely need to find a solution with automation, but there are clone and move apps that are easier to configure and easy for users to use.

For example, [Elements Copy \& Sync](https://marketplace.atlassian.com/apps/1211111/elements-copy-sync-jira-issue-sync?hosting=cloud&tab=overview&utm_source=community&utm_medium=forum&utm_campaign=question) could work for you by letting developers chose a copy recipe "Add to Development" where you've pre-configured the issue type and the user selects from the projects made available for the recipe.

You can see how it works in this video <https://youtu.be/uxcOT2imgHQ>


Tags: cloud