Forums

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

Set multiple services to Affected Services field based on a string

Renatão November 22, 2023

I have an issue that is automatically created in JSM by another tool. This issue always contains a string like this:

Ambiente: XPTO
Serviços: ServiceA, ServiceB, ServiceC
Emissores impactados: XYZ, KUO, BMN

The list of "Serviços" is variable. There can be at least one. The name of de services listed in this field is the same as the name of Services assets.

I created an automation that is supposed to "convert" this string of services and set each one in "Affected Services" field.

So, the first thing I did was to create a branch to iterate each service:

image.png

It worked. The result of the action above is an array:
[Service A]
[Service B]
[Service C]

Then, I looked up the object in the Assets:
image.png

It also worked.

And then, last I updated the Affected Services field adding the object loaded before:
image.png

 

This is the code above:

{
"update": {
"Affected services" :
[{"set":[
{{#lookupObjects}}
{"id":"{{Service ID}}"}
{{^last}}, {{/}}
{{/}}
]
}]
}
}

I found the information above in Atlassian community. 

Problem: It seems that the update bellow runs only once, even with the iteration running. I know that the iteration runs asynchronously and I don´t mind the order of the services to be included. But, only one service is included in my list.

I put some logs in the automation, and there are the results:

image.png
image.png

 

 

And here is the issue that was used in the automation above:

image.png

As you can see, only one of the three services is included in the list of "Affected Services". In this case, it was the first one, but I tried it so many times and the behaviour is random (sometimes the second, sometimes the last service).

Based on the logs, my assumption is that the "Edit Field" step is running only once. Does anyone knows an alternative to this problem?

3 answers

1 accepted

0 votes
Answer accepted
Renatão November 23, 2023

This was the solution provided by Atlassian Support:

 

Findings
As you are using a branch to edit the same issue, the values are being set in a race condition. You must add them at once.

Next steps

Remove the branch (keeping its actions), and update the AQL on your lookup action as follows:

Name in ({{issue.description.substringBetween("Serviços: ","Emissores").split(",").trim()}})
0 votes
Renatão November 23, 2023

This was the solution provided by Atlassian support:

 

Findings
As you are using a branch to edit the same issue, the values are being set in a race condition. You must add them at once.

Next steps

Remove the branch (keeping its actions), and update the AQL on your lookup action as follows:

Name in ({{issue.description.substringBetween("Serviços: ","Emissores").split(",").trim()}})
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.
November 22, 2023 edited

Hi @Renatão 

First thing, I am not using JSM with assets and so cannot test my suggestions.  

Your advanced edit with JSON is using a set operation, inside of the iterator on your Services.  And so it is possible the objects are getting repeated replaced, and the last one "wins".

Have you instead tried using an add operation for "Affected services" in the JSON?

Kind regards,
Bill

Renatão November 22, 2023

Hi!
Yes, I tried. But the following error was found:

(Field with id' customfield_10034' and name 'Affected services' does not support operation 'add' Supported operation(s) are: 'set')
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.
November 22, 2023

That is unfortunate...and will instead require performing one single update to add all of the services at one time.

Can the services be added by name rather than id value?  If so, instead of using the advanced branch over the services, an iterator could be used to create a single JSON expression to add them at one time...or perhaps even edit without the JSON using the field drop-down list for Affected Services and a smart value list.

Renatão November 22, 2023

No, the services must be added by Service ID, and JSON is also mandatory (according to my investigation).

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.
November 22, 2023 edited

That is unfortunate, and this seems more challenging to solve.

I can only think of one other option if there are not that many possible Services:

  • Using created variables and Lookup Objects, look up and store every possible Service ID.  For example, varServiceAId, varServiceBId, varServiceCId, etc.
  • Using an iterator over your selected Services, pre-build the JSON for the "set" and store that in a created variable.  Instead of the id, use your Service name in its place in the expression.
    • variable name: varServiceJson
    • smart value:
{
"update": {
"Affected services" : [
{
"set" : [
{{#your expression to gather the service names}}
{ "id" : "{{.}}" }{{^last}}, {{/}}
{{/}}
]
}
]
}
}
  • Use the replace() function repeatedly to substitute the id values for the names.  For example:
    • {{varServiceJson.replace("ServiceA",varServiceAId).replace("ServiceB",varServiceBId).replace("ServiceC",varServiceCId)}}
  • perform one update using that updated JSON expression
  • test thoroughly

 

If you decide to try this, I recommend writing each variable to the audit log as they are created / updated.  That will help diagnose any problems.

Renatão November 22, 2023

I would not like to go on this way. Really. I don't know how many services may be affected by a high impact incident.

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.
November 22, 2023

In that case you may want to contact Atlassian Support to see if they have other options: https://support.atlassian.com/contact/#/  Please add a link to this thread in your support ticket so they can see what you tried.

When you hear back from them, please post what you learn to benefit the community.  Thanks!

Like Renatão likes this
Renatão November 23, 2023

Thank you for the suggestion. I´ve just created a ticket at Atlassian support and as soon as I get the answer, I´ll write it down here.

Renatão November 23, 2023

Atlassian replied me with a simple instruction that has worked perfectly.

 

Findings
As you are using a branch to edit the same issue, the values are being set in a race condition. You must add them at once.

Next steps

Remove the branch (keeping its actions), and update the AQL on your lookup action as follows:

Name in ({{issue.description.substringBetween("Serviços: ","Emissores").split(",").trim()}})
Like Bill Sheboy likes this
Wesley Wong
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 2, 2025

Hi Renatao, I have a very similar setup that I am trying to acheive.

Would you be able to share with me how your full rule looks like?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
atlassian, atlassian community, loom ai, atlassian loom ai, loom, atlassian ai, record recaps of meetings, meeting recaps, loom recaps, share meeting recaps,

Loom’s guide to great meetings 📹

Join us to learn how your team can stay fully engaged in meetings without worrying about writing everything down. Dive into Loom's newest feature, Loom AI for meetings, which automatically takes notes and tracks action items.

Register today!
AUG Leaders

Atlassian Community Events