Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Copy custom field value from SQL item search (foreach branch) to current work item

Céline - Maestrel
Contributor
July 9, 2025

Hello,

I have a question that is probably simple, but I can not figure it out and would appreciate the help of the Atlassian community. 

It is on a JSM project.

When a work item is created:

  • browse if there are existing work item from same reporter (OK)
  • go through all existing work item from this reporter (foreach branch) and check if a specific custom field is not empty (OK)
  • copy the value of this custom field (from the work item of the foreach) to the work item that triggered the rule 

The last part is where I struggle.

  • I have tested with "Edit work item", but it edits the work item of the foreach branch.
  • I have tested with "Set issue property" (but it the property is associated to the work item browsed in the foreach branch, not to the work item that triggered the automation).

It seems to me that it should be rather simple, and that I am missing something... 

With many thanks!

Céline

 

Edited July 15th - Additional information

Scope: JSM Service project

Aim: use the latest value provided of a custom field (WordPress Username) by a reporter that already created work items (same reporter and same "Purchase code" custom field) to populate the custom field "WordPress Username" for the newly created ticket, when this latter has no "WordPress Username" provided.

Here is a summary of the options I have explored

  • Option A : Using JQL in a foreach branch: it seems that I can not refer back to the work item that triggered the rule, once I am in the branch looping through other work item. My conclusion is that this was not possible.
  • Option B: Using JQL in a foreach branch and create a variable that should hold the value of the custom field "WordPress Username" of the more recently created found work item, for which it has been provided. It seems that I can not access the variable outside the foreach branch. Why??
  • New Option C: Using "Lookup items". This is what I will test next.

Why is Option B not working??

Automation Rule for Option B

Automation- Rule-Variable-Branch.png

Audit log for Option B

Audit-log-Automation-Variable-Branch.png

2 answers

1 accepted

0 votes
Answer accepted
Trudy Claspill
Community Champion
July 9, 2025

Hello @Céline - Maestrel 

I have a questions about this step:

  • copy the value of this custom field (from the work item of the foreach) to the work item that triggered the rule 

1. What type of field is the custom field?

2. Is the field into which you want to copy the data the same field in the trigger issue? Are trying to copy from field "A" in the found issue to field "A" in the trigger issue?

3. If the answer to #2 is "no" then what is the field type of the trigger issue field into which you are trying to copy the data?

4. What do you require the end result to be when you have found multiple issues where the custom field is not empty? Do you expect all the various values of those fields to be copied into the one destination field in the trigger issue?

Céline - Maestrel
Contributor
July 15, 2025

Hello Trudy.

Thank you.

1. There are 3 fields: a URL, and 2 short-text field.

2. Yes, they are the same field "A" that I wish to copy from found issue to triggered issue.

3. I wish to take the one from the most recent issue found.

I have edited my question with more details. Thank you for asking!

Trudy Claspill
Community Champion
July 15, 2025

Thank you for the additional information.

@Marc - Devoteam provided an answer for why Option B is not working. For more information on that refer to this KB:

https://support.atlassian.com/automation/kb/parallel-execution-of-branches-can-produce-unexpected-outcome/

I believe you will need to use the Lookup Issue action rather than branching to achieve your requirement.

Use the same JQL you used in your Branch.

Screenshot 2025-07-15 at 12.37.26 PM.png

Follow that with an Advance Compare / smart values Condition to check that you got at least one issue back:

{{looupIssues.size|0}} is greater than 0

Follow that with an Edit action. Since this is all happening in the main line of the rule, the Edit action will apply to the trigger issue.

To set a field in the trigger issue to a value found in the most recently created issue in the Lookup results, given that you have ordered those results by Created ASC, you would reference the last issue in the results set. In your Edit action select the field you want to set, and then set it to this smart value:

{{lookupIssues.last.<your custom field>}}

Céline - Maestrel
Contributor
July 17, 2025

Hi,

Yes, "Lookup items" is a straightforward way to achieve what I need. Thank you @Trudy Claspill for pointing me in the right direction, and thank you @Marc - Devoteam for your valuable input regarding Option B.

Here is my updated rule (working exactly as I need it):

Lookup item rule.png

Like Trudy Claspill likes this
Trudy Claspill
Community Champion
July 17, 2025

I recommend that after the Lookup action you add an Advance Compare / smart values Condition to check that you got at least one issue back:

{{looupIssues.size|0}} is greater than 0

Otherwise you may get unexpected results or an error in the following Log actions and Edit actions when no issue is found by the Lookup.

0 votes
Marc - Devoteam
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.
July 9, 2025

HI @Céline - Maestrel 

Whenever you ask for help with an Automation Rule it will help us to help you if you provide:

1. what type of project is this (e.g., company-managed, team-managed, etc.), 

2. images that show your complete rule.

3. images showing the details of any relevant actions/conditions/branches.

4. images showing the Audit Log details for the rule execution.

5. Explain where the issue is.

These questions are not for not willing to help, but to have community members understand on how automation works.

Céline - Maestrel
Contributor
July 15, 2025

Hi,

Thank you. I have edited my question with screenshots and updated information. 

Marc - Devoteam
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.
July 15, 2025

Hi @Céline - Maestrel 

You are creating the variable in the branch, a branch runs parallel.

The rest of the actions in the rule, don't know this variable, if you want to use a variable like this, you will need to create it before the branch.

Céline - Maestrel
Contributor
July 17, 2025

Hi Mark,

Thank you for your explanation, very clear!

Can I create it before (initialize it to empty for example?) and then update its value in the branch? I will then be able to use the variable outside the branch (with its value taken from the branch)?

For my specific question, the solution was the "Lookup items", but I am glad to have now a better understanding of how to use the variable. Thanks!

Marc - Devoteam
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.
July 17, 2025

HI @Céline - Maestrel 

Please accept my answer as a solution, if my answer helped to solve your request.

This will help other community member trying to solve the same.

P.S. If the answer is very valuable to you, please share some kudos.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events