Automation to tag user from one in three custom fields in ticket description upon creation

Raycher December 10, 2024

Hi everyone!

At the moment I have a system where a new issue is created by automation when the trigger issue is transitioned to a 'Ready' status.

In the 'Description' of the newly created ticket, I am trying to get automation to tag a user based on which user custom field (out of three) is not empty. These three custom fields are on both the trigger and created issue, and the created issue is copying the value of these three fields from the trigger issue

So ideally the automation would reference Custom Field 1

  • if it is filled, it will tag the user from that field
  • if it is not filled it will reference Custom Field 2 

Custom Field 2

  • if it is filled, it will tag the user from that field
  • if it is not filled it will reference Custom Field 3

Custom Field 3

  • if it is filled, it will tag the user from that field
  • if it is not filled, it will return a note [no users found]

I've tried the following smart value: 

{{#if(customfield_1)}}@[~{{customfield_1}}] 

{{else}}

{{#if(customfield_2)}}@[~{{customfield_2}}]

{{else}}

{{#if(customfield_3)}}@[~{{customfield_3}}]

{{else}}[No user selected] {{/}}{{/}}{{/}}

but to no avail, i've tried including .accountid behind each custom field value, it also does not return anything. I'm no expert on this, so would apperciate any help on this. 

Thank you!

2 answers

1 accepted

2 votes
Answer accepted
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.
December 11, 2024

Hi @Raycher 

There is a format of the conditional logic which supports nesting: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/#if

{{if(smartValue, "value if true", "value if false")}}

 

Thus for your case, it could be this:

{{if(customfield_1.accountId.isNotEmpty(), 
customfield_1.accountId,
if(customfield_2.accountId.isNotEmpty(),
customfield_2.accountId,
if(customfield_3.accountId.isNotEmpty(),
customfield_3.accountId,
"No values selected")))}}

However with this syntax, the mention syntax could not be used in the conditional logic.

The workaround is to first create two created variables, one for the prefix and one for the suffix of the mention, and then concatenate the values:

  • action: create variable
    • name: varMentionPrefix
    • value: @[~
  • action: create variable
    • name: varMentionSuffix
    • value: ]

And to get the total expression:

{{if(customfield_1.accountId.isNotEmpty(), 
varMentionPrefix.concat(customfield_1.accountId).concat(varMentionSuffix),
if(customfield_2.accountId.isNotEmpty(),
varMentionPrefix.concat(customfield_2.accountId).concat(varMentionSuffix),
if(customfield_3.accountId.isNotEmpty(),
varMentionPrefix.concat(customfield_3.accountId).concat(varMentionSuffix),
"No values selected")))}}

 

Kind regards,
Bill

Raycher December 11, 2024

Hey Bill,

Thank you so much for this! The code you provided worked perfectly in returning the account id of the user in one of the three fields, however when executed the @ returned an unknown user. 

So instead of using the 'Create Variable' function for the mention syntax, I used it to return the Account ID from the three custom fields:

  • action: create variable
    • name: varSelectedUser
    • value: 
      {{if(customfield_1.accountId.isNotEmpty(), 
      customfield_1.accountId,
      if(customfield_2.accountId.isNotEmpty(),
      customfield_2.accountId,
      if(customfield_3.accountId.isNotEmpty(),
      customfield_3.accountId,
      "No values selected")))}}

I then used the variable in the description of the created ticket as followed:

[~accountid:{{varSelectedUser}}]

and it worked perfectly!! Thank you so much @Bill Sheboy you helped solve a huge headache for me! 

Like Bill Sheboy likes this
0 votes
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 11, 2024

Hello @Raycher 

Are the three fields you are checking in the trigger issue or the new issue you created?

When asking for help with an automation rule it will help us help you if you provide:

1. Screen images showing the entire rule

2. Screen images of any actions, branches, or conditions that are relevant to your question

3. The output in the rule Audit Log from when the rule executed.

Raycher December 11, 2024

Hey Trudy!

Apperciate your response, the three fields are present on both the trigger and created issue - the values are copied over from the trigger onto the created. 

I don't think I'll be able to share SS due to confidentiallity issues, apologies on that. The actual rule is also very long and not really relevant to this specific issue I'm trying to fix. 

I am happy to provide more information if necessary! 

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 11, 2024

Hello Raycher,

Without the details of the rule it will be difficult for us to provide assistance. Unexpected or incorrect rule behavior can be caused by the context in which steps are executed. We can't asses the context without the rule details.

In what type of rule component are you trying to use your code? Is this within the same Create Issue action you are using to create the issue, or in a separate Edit action?

If it is in the Create Issue action, then the three fields are not yet set within that issue, so they can't be used in your code. You would have to reference the values from the fields in the trigger issue. You could try prefixing the custom field references with triggerIssue.

Raycher December 11, 2024

That's right, it is within the same Create Issue action in the description section. I've tried using the triggerIssue as reference but no luck as well. Is the code that was provided valid? Or does something looks off? 

If this does not work I may just create a seperate automation for this. 

Suggest an answer

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

Atlassian Community Events