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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Can I use automation to copy existing issues' custom fields info to a newly created issue's fields?

When I create a new issue, I would like to use automation to copy information from a previously created issue's custom fields into fields within the newly created issue that triggers the automation. I was hopeful that {{lookupIssues}} would provide the answer for this, but it does not support custom fields. Is there some way, using automation, that I can do what I am wanting to do?

I tried to use branching with JQL to get the previously created issue, and then use it to update the newly created issue; but with that approach, my only choice appears to be to update from the newly created issue to the branched issue, rather than from the branched issue to the newly created issue. I also tried to create a variable with the value from the branched issue's field so that I could use it for later copying after returning from the branch, but the variable doesn't carry forth beyond the confines of the branch, so that didn't work.

I've scoured the message boards for a solution, but haven't found one.

2 answers

1 accepted

Here's how I ultimately did this.

1) I used a Send web request with the following as the Webhook URL. (I entered the type of issue to search for where it says <myIssuetype>. For instance, Task.)

https://<mySite>.atlassian.net/rest/api/3/search?jql=project%20%3D%20{{issue.project.key.urlEncode}}%20AND%20issuetype%20%3D%20<myIssuetype>&ampfields%20%3D%20*all

2) Then I used Edit issue to select most of the fields from the “Choose fields to set” dropdown and used these as the basic templates for the new values:

  • For the Description field: {{webhookResponse.body.issues.fields.description.get(0).content.get(0).content.text}}
  • For Text Field (single line) or Number Field fields: {{webhookResponse.body.issues.fields.<fieldname>}}
  • For Select List (single choice) fields: {{webhookResponse.body.issues.fields.<fieldname>.value}}
  • For User Picker (single user) fields: {{webhookResponse.body.issues.fields.<fieldname>.accountId}}
  • For User Picker (multiple users) fields: {{webhookResponse.body.issues.fields.<fieldname>.get(0).accountId}}

I ran into a problem where a User Picker field of the source issue had a null value and would cause an error that stopped my rule from working. The solution to that problem was the following. Instead of selecting the field from the “Choose fields to set” dropdown like described above, I used the More options > Additional fields box and entered the following JSON for the User Picker field. (My User Picker field was "customfield_10047"):

{
  "fields": {
    "customfield_10047": [
     {{#webhookResponse.body.issues.fields.customfield_10047}}
        {{accountId.asJsonObject("accountId")}}{{^last}},{{/}}
      {{/}}
    ]
  }
}

I found the above solution for my User Picker field's problem here, provided by @Erik Buchholz. Thanks Erik!

0 votes
Esther Strom Community Leader Oct 15, 2020

Hi, @Marc Pincince - I don't have an answer for you yet, but if you can give a bit more info I'll see if I can figure out it, since I can see this being useful.

Just to make sure, you're using the Issue Created trigger in the automation rule, so this is something you want to run every time an issue in this specific project runs (or in multiple projects, if you're using a global rule.) Correct?

Is the issue that you want to copy the values from static? Do you always want to copy the values from ticket ABC-123, or does the "source" ticket need to vary based on some criteria?

Thanks @Esther Strom.

This is the third time I try to reply to you, so my apology if you receive multiple responses; but each time I click reply, my response disappears and I cannot find it, so I'm trying to reply yet again, after restarting my browser.

Yes, I am using the Issue Created trigger in the automation rule and this is something I want to run every time an issue in this specific project runs (every project runs, as in the global rule scenario).

I’ll eventually want this to copy values from dynamic source issues, but for now a static source-based solution would suffice, I think—just to get things moving. My eventually envisioned scenario is: When a new issue is created, if that newly created issue is of a specific type (let’s say type A) then automation would look for a specific previously existing issue (let’s say issue 1) and copy its pertinent fields’ information into the newly created issue; else if that newly created issue is of a different specific type (let’s say type B) then automation would look for a different specific previously existing issue (let’s say issue 2) and copy its pertinent fields’ information into the newly created issue; etc..

Since I first asked this question, I have tried several different things to accomplish this. My most recent attempt involves:

1) Using Send web request with this as the Webhook URL:

https://mySite.atlassian.net/rest/api/3/search?jql=project%20%3D%20{{issue.project.key.urlEncode}}%20AND%20issuetype%20%3D%20Development

2) Then I use Edit issue to select the Description field from the “Choose fields to set” dropdown and use this as the new value for the Description field: {{webhookResponse.body.issues.fields.description}}

I’m now getting {version=1, type=doc, content=[{type=paragraph, content=[{type=text, text=Development}]}]} as the new field information for the newly created issue. What I really want is just what I would usually get when copying a field from one issue to another. In this case, it should just be the word “Development,” which follows the “text=” in what is being copied. I think what I really need is to somehow extract the content for type paragraph portion? I’m new to working with APIs and don’t know how to extract this. Maybe it has to do with expand? I'm not sure how to add expand to the Webhook URL. The documentation isn’t clear to me.

I do feel like I’ve made progress, as I have been able to find the desired source issue and extract the desired field’s information. I just need to figure out how to get the correct portion of that field’s information now, I think. I can certainly use your help figuring out/learning how to do that, or a better way.

Thanks again.

@Esther Strom ,

I got it to "work" by changing the Edit issue step so that instead of using {{webhookResponse.body.issues.fields.description}} as the information to copy as the new value for the Description field, I am now using {{webhookResponse.body.issues.fields.description.get(0).content.get(0).content.text}}. But, I don't know whether this is the best approach. It looks like a lot of typing is ahead of me this way, to address all of the fields I intend to copy.

I'm definitely open to suggestions. Thanks.

Esther Strom Community Leader Oct 20, 2020

Wow, @Marc Pincince you got way further into this than I have yet. Good job getting it to work at all. I can't answer if this is the best way to do it or not, but I'll keep looking and see if there are any other ways.

Just out of curiosity, do you have ScriptRunner? That might be a way to go, instead of automation.

No @Esther Strom. We don't have ScriptRunner. Trying to stay within what with already paid for with Jira Software as much as possible instead of purchasing additional Apps, at least for the moment. 

Anyhow, I've pretty much built out my solution within Automation now, using Send web request and {{webhookResponse.body.issues.fields}} as described above, and it seems to be working. I learned a few things along the way regarding {{webhookResponse.body.issues.fields}}. The basics of which were:

  • For Text Field (single line) or Number Field fields use:{{webhookResponse.body.issues.fields.<fieldname>}}
  • For Select List (single choice) fields use:{{webhookResponse.body.issues.fields.<fieldname>.value}}
  • For User Picker (single user) fields use:{{webhookResponse.body.issues.fields.<fieldname>.accountId}}
  • For User Picker (multiple users) fields use:{{webhookResponse.body.issues.fields.<fieldname>.get(0).accountId}}
  • For the Description field use:{{webhookResponse.body.issues.fields.description.get(0).content.get(0).content.text}}

I was able to simply add these {{webhookResponse}} entries to the individual text boxes for each field I wanted to update in the Edit issue component of the rule. (Alternatively, I could have used the More options, Additional fields box and done my updates there via JSON if I had wanted, but they all worked out just fine using the individual text boxes.) You have to remember to hit the enter key for most of the entries to manifest themselves into the text boxes and can't scroll within some of the the text boxes to see the entirety of what you typed after entry; but for those that you can't scroll within, you can hover over them and a tooltip of the entry will appear so you can verify you correctly entered the information.

 

Like Esther Strom likes this

No @Esther Strom . We don't have ScriptRunner. Trying to stay within what with already paid for with Jira Software as much as possible instead of purchasing additional Apps, at least for the moment. 

Anyhow, I've pretty much built out my solution within Automation now, using Send web request and {{webhookResponse.body.issues.fields}} as described above, and it seems to be working. I learned a few things along the way regarding {{webhookResponse.body.issues.fields}}. The basics of which were:

  • For Text Field (single line) or Number Field fields use:{{webhookResponse.body.issues.fields.<fieldname>}}
  • For Select List (single choice) fields use:{{webhookResponse.body.issues.fields.<fieldname>.value}}
  • For User Picker (single user) fields use:{{webhookResponse.body.issues.fields.<fieldname>.accountId}}
  • For User Picker (multiple users) fields use:{{webhookResponse.body.issues.fields.<fieldname>.get(0).accountId}}
  • For the Description field use:{{webhookResponse.body.issues.fields.description.get(0).content.get(0).content.text}}

I was able to simply add these {{webhookResponse}} entries to the individual text boxes for each field I wanted to update in the Edit issue component of the rule. (Alternatively, I could have used the More options, Additional fields box and done my updates there via JSON if I had wanted, but they all worked out just fine using the individual text boxes.) You have to remember to hit the enter key for most of the entries to manifest themselves into the text boxes and can't scroll within some of the the text boxes to see the entirety of what you typed after entry; but for those that you can't scroll within, you can hover over them and a tooltip of the entry will appear so you can verify you correctly entered the information.

Like Esther Strom likes this

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you