Forums

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

Automation: 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

2 answers

0 votes
Bill Sheboy
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 

Once the rule is inside of the branch to work items, the scope is now those work items: it cannot edit the trigger one.

Perhaps use the Lookup Work Items action with a JQL expression to find the ones you need, and then reference the {{lookupIssues}} smart value (outside of branching) to update the trigger work item.

Kind regards,
Bill

0 votes
Anandhi Arumugam _Cprime_
Community Champion
July 9, 2025

Hi @Céline - Maestrel I believe you are building this solution using Automation rule. I have a question generally where

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

Say, a reporter Mr.X has created IT-12 (with Field A: "ASD"), IT-14 (with Field A: "<Empty>"), IT-15 (with Field A: "<Empty>") in the past. Now he has created IT-16 (with Field A: "AWD"), which will trigger the Automation Rule.

Now,  the system will go through the issues and identify the issues IT-12, 13 and 14. Now the system will copy the value from IT-16 to IT-14 and IT-15. But is it just one value that should be used for the field? What are the other values? How do you check the relevance to the issues where it is empty?

Céline - Maestrel
Contributor
July 9, 2025

@Anandhi Arumugam _Cprime_ Thank you!

  • I wish to update the field of newly created work item only if it is empty. Got this covered OK
  • In my SQL search, I order the result. I will to copy the latest one set (if there have been various work items with this field set).

I have as well tested to use Variables (as it seems more appropriate than Issue property), but I still can not make it work...

Rule - Using Issue property

Using entity property.png

 

Rule - Using Variables

Using variables.png

 

Results of both rules

For both rules, I have the correct values logged in the branch. I know that I have retrieved what I need. However, I can not figure out how to use these values to update the work item that triggered the rule  (the one not in the branch), to be updated with these values.

 

Like John Funk likes this
Céline - Maestrel
Contributor
July 9, 2025

In other terms, here is a summary of my different questions:

  • how do I set a value for a field of the work item that triggered the automation, when I am in a foreach branch that loop on other work items?
  • how do I use a variable (created in the foreach branch) to set the value of a work item field as the value of the variable? I wish to use the variables outside the branch.
  • Additional question : in my context, would it be best to use "Lookup items" rather than a SQL condition with a foreach?

Thank you!

Like John Funk likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events