Hello,
I'm looking to use jira automation rules in an advanced way using variables in smart value functions.
I saw that a ticket covered this topic some time ago but even though it is marked as resolved I am having trouble applying the syntax.
Here is the ticket : https://codebarrel.atlassian.net/browse/AUT-168
I want to do the same, e.g. :
{{issue.summary.replace("blah", "{{issue.fields.reporter.displayName}}")}}
Is there a way to use variables in smart value functions?
Yes, that works. If you remove the quotation marks and extra curly braces that would work. For example:
{{issue.summary.replace("blah", issue.reporter.displayName)}}
Best regards,
Bill
Hi @Bill Sheboy
Thanks a lot for your answer.
I tried to combine your solution with a variable added by "Create variable"
But I failed to use this variable in the replace method. This didn't return anything using the variable whereas it did return something when I directly used values like fieldChange.fromString and fieldChange.toString (the trigger of my action is a change of a field)
Instead of using a custom variable, I used a way to concat "[" and "]" with another topic (https://community.atlassian.com/t5/Jira-questions/Smart-value-with-concatenate-string-in-string-replace-replaceAll/qaq-p/1363587)
Here is my final code that do what I want to do :
{
"fields": {
"summary": "{{issue.summary.replace(fieldChange.fromString.left(0).concat("[").concat(fieldChange.fromString).concat("]"), fieldChange.toString.left(0).concat("[").concat(fieldChange.toString).concat("]"))}}"
}
}
There is probably some way to make it prettier but I stop my search here!
Thanks again !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, and I am glad you got that to work!
Regarding Create Variables, they definitely need some investigation and improvements to be a more useful tool for automation rules. Currently, I have only found them useful to build JSON strings for complex edits and to remove things from lists (e.g. Components).
Best regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have discovered a similar issue, where I am unable to use earlier created variables as function arguments in smart values, and the workaround is to use issue entity properties instead:
https://community.atlassian.com/t5/Jira-Service-Management/Re-Pass-in-function-parameters-by-reference-in-smart-val/qaq-p/1806987/comment-id/87452#M87452
For some issue, which has at least 6 comments, automation goes as follows...
Create smart variable:
Variable name: commentNumber
Variable value: 5
Set entity property for issue:
property name: prop_commentNumber
property value (JSON):
{"val": {{commentNumber}} }
Log action:
{{issue.comments.get(issue.properties.prop_commentNumber.val)}}
Is it the best approach at this moment, and there is a bug in accessing list elements via smart variable values?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Boris,
Did you figure this out?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
I am trying to get something similar too. Anyone got this working. I am filtering a list of email address (about 3 or 4) and want to filter out only example.com emails and the string example.com is in a variable domain - I would like to do something like:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just retested this to answer another question: the match() function still cannot accept variables for a regular expression for Jira Cloud.
And...if you are using Server/Data Center I also doubt this would work as those versions do not have Create Variable with which to make the regular expression dynamic.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the response @Bill Sheboy - that is a pity. We are on Jira Cloud.
I wonder if anyone else has got this working or found a workaround apart from hardcoding the domain (or anything else) instead of using the variable.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
After a bit more research, I found a work-around I created a year ago for this problem, bypassing the need to use the match() function:
CompanyName1|CL1,CompanyName2|CL2,CompanyName3|CL3,
{{issue.reporter.emailAddress.substringAfter("@").substringBefore(".")}}
{{varClientIdList.substringAfter(varReporterEmailDomain.concat("|")).substringBefore(",")}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I can't seem to get the replace to work for me and I can't figure out what I'm doing wrong.
Here is my one variable:
Here is a second variable that contains my Jira Smart value. I put the word REPLACE in there for what I want to replace later.
I then try to use the following:
{{theThing.replace("REPLACE",theChoice)}}
Which I would hope would result in
{{issue.properties."proforma.forms.i1".design.questions.1.choices.get(0).label}}
But it does not work.
Anyone know what I'm missing?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There may be some missing context here...
Would you please post an image of your entire rule, images of the actions which perform that replace, and of the audit log details? Those may help to explain what you are observing.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy sure thing! (I just noticed my one screenshot didn't come through in the previous post.
My rule is very simple right now as I'm just trying to test out this specific replace functionality before I put it into my real purpose.
My rule just...
1. Triggered manually
2. Sets the first variable to 1
3. Sets the 2nd variable as seen
4. Comment on the ticket with my attempt at the replace (so I could see if it worked)
And here is the audit log. It makes the comment on the ticket, but only the top, hardcoded line works. The replace does not.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you write {{theThing}} to the audit log, what do you observe?
What is being written to the comment added?
Side note: I do not know which version of Jira you are using, but if you are using Jira Cloud and you are on Standard or Free license, consider only writing to the audit log for test rules, rather than writing to issues with comments. Otherwise that will start counting against your limits next month. Please look here for more information: https://community.atlassian.com/t5/Automation-articles/Introducing-our-new-packaging-model-for-Jira-Cloud-Automation/ba-p/2446099
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy ah great idea! I never thought of that! I'm on Cloud Premium.
So it appears my issue is the variable {{theThing}} is not getting set. It doesn't like me passing in a smart value.
Is there a way for me to force it to accept a literal string?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Progress!
I see what your image is showing to create {{theThing}}. Please describe what that is meant to contain, as it may be the expression to build it has a problem.
It appears you may be trying to replace text in an issue property using some value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy if you look at my previous post above under #3, you'll see I am attempting to set that value to a specific smart value. My objective is to replace the word "REPLACE" with a number (whatever the user selects in a previous step).
I realize in my example above I have it hardcoded to 1. But that won't be the case in real life. In actuality, I'm simply trying to dynamically use the Jira smart value you see in the screenshot above under #3.
In order to do that, I'm trying to replace the word "REPLACE" with the correct number. But Jira doesn't seem to like me trying to set the variable to a literal string of a smart value. I assume it's trying to interpret that value (which will return nothing until the replace function works).
So the end result (if the replace worked) should be this:
{{issue.properties."proforma.forms.i1".design.questions.1.choices.get(0).label}}
And if I hardcode that, it works just fine. But I can't get it to be dynamic by passing in the selected number.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Because that created variable is empty, my hypothesis is the property is one of those dynamic smart values which can only be evaluated in certain ways. (I am not using ProForma, so I am guessing a bit here...)
Let's confirm that by writing these to the audit log with separate actions:
form design: {{issue.properties."proforma.forms.i1".design}}
all questions: {{issue.properties."proforma.forms.i1".design.questions}}
question ID 1: {{issue.properties."proforma.forms.i1".design.questions.1}}
all choices: {{issue.properties."proforma.forms.i1".design.questions.1.choices}}
first choice: {{issue.properties."proforma.forms.i1".design.questions.1.choices.get(0)}}
all of it: {{issue.properties."proforma.forms.i1".design.questions.1.choices.get(0).label}}
This should confirm at which point the value can be grabbed into a variable. After that, we can continue the parsing using text and list functions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy Here are the results. I cleaned it up in notepad so it was slightly easier to read.
form design: {settings={templateId=1, name=Product Management Request, portal={canSubmit=true}, submit={lock=false, pdf=false}, templateFormUuid=3aa949cf-de0d-4d82-a668-752a0ef9e5fc}, layout=[{version=1, type=doc, content=[{type=extension, attrs={extensionKey=question, extensionType=com.thinktilt.proforma, layout=default, parameters={id=1}, localId=8d849933-8ed1-4e65-bf05-f1bde6a60895}}]}, {version=1, type=doc, content=[{type=extension, attrs={extensionKey=question, extensionType=com.thinktilt.proforma, layout=default, parameters={id=6}, localId=572ec7a3-4954-483c-b922-08f75d4d5079}}]}, {version=1, type=doc, content=[{type=extension, attrs={extensionKey=question, extensionType=com.thinktilt.proforma, layout=default, parameters={id=8}, localId=0d6a8fbc-da6e-412a-a551-dc3e5a663f13}}, {type=extension, attrs={extensionKey=question, extensionType=com.thinktilt.proforma, layout=default, parameters={id=9}, localId=2e33f2b8-bc10-49f8-a802-e8a9a3058b7f}}, {type=extension, attrs={extensionKey=question, extensionType=com.thinktilt.proforma, layout=default, parameters={id=10}, localId=ee748136-cf8b-4fe0-998a-16cdc5d61a49}}, {type=extension, attrs={extensionKey=question, extensionType=com.thinktilt.proforma, layout=default, parameters={id=11}, localId=7f8fb1a4-39ea-4f01-baea-ae22c3d24fd6}}]}, {version=1, type=doc, content=[]}, {version=1, type=doc, content=[{type=extension, attrs={extensionKey=question, extensionType=com.thinktilt.proforma, layout=default, parameters={id=15}, localId=1bddd08d-fc1f-4957-99a3-f2f69522eb23}}, {type=extension, attrs={extensionKey=question, extensionType=com.thinktilt.proforma, layout=default, parameters={id=18}, localId=8121c1cd-c5cc-4591-a6b2-ba6669557833}}, {type=paragraph, content=[]}]}], conditions={5={i={co={cIds={1=[1]}}}, o={sIds=[1]}, t=sh}, 7={i={co={cIds={6=[1]}}}, o={sIds=[2]}, t=sh}, 12={i={co={cIds={6=[2]}}}, o={sIds=[3]}, t=sh}}, sections={1={name=My Application, conditions=[5]}, 2={name=Yes, conditions=[7, 5]}, 3={name=My Application No, conditions=[12, 5]}, 4={name=Always, conditions=[]}}, questions={8={type=ob, label=Client, description=, validation={rq=true}, choices=[{id=f97360e7-cbd8-4076-9dec-22740d1c40f8:42022, label=-DIN - x - TEST - ABC Mortgage}], jiraField=customfield_15065, questionKey=}, 10={type=ts, label=App Username, description=i.e. CXX, validation={rq=false}, choices=[], questionKey=}, 18={type=rt, label=Description, description=, validation={rq=true}, jiraField=description, questionKey=}, 15={type=ts, label=Summary, description=, validation={rq=true}, jiraField=summary, questionKey=}, 11={type=ts, label=Vault Username, description=Username under which docs are uploaded, validation={rq=false}, choices=[], questionKey=}, 9={type=ts, label=Tenant ID, description=Does it differ, validation={rq=false}, choices=[], questionKey=}, 6={type=cd, label=Is this request for a new client?, description=, validation={rq=true}, choices=[{id=1, label=Yes, other=false}, {id=2, label=No, other=false}], questionKey=}, 1={type=cd, label=Type of Request, description=, validation={rq=true}, choices=[{id=1, label=My Application, other=false}, {id=2, label=Other, other=false}], questionKey=}}}
all questions: {8={type=ob, label=Client, description=, validation={rq=true}, choices=[{id=f97360e7-cbd8-4076-9dec-22740d1c40f8:42022, label=-DIN - x - TEST - ABC Mortgage}], jiraField=customfield_15065, questionKey=}, 10={type=ts, label=App Username, description=i.e. CXX, validation={rq=false}, choices=[], questionKey=}, 18={type=rt, label=Description, description=, validation={rq=true}, jiraField=description, questionKey=}, 15={type=ts, label=Summary, description=, validation={rq=true}, jiraField=summary, questionKey=}, 11={type=ts, label=Username, description=Username under which docs are uploaded, validation={rq=false}, choices=[], questionKey=}, 9={type=ts, label=Tenant ID, description=Does it differ?, validation={rq=false}, choices=[], questionKey=}, 6={type=cd, label=Is this request for a new client?, description=, validation={rq=true}, choices=[{id=1, label=Yes, other=false}, {id=2, label=No, other=false}], questionKey=}, 1={type=cd, label=Type of Request, description=, validation={rq=true}, choices=[{id=1, label=My Application, other=false}, {id=2, label=Other, other=false}], questionKey=}}
question ID 1: {type=cd, label=Type of Request, description=, validation={rq=true}, choices=[{id=1, label=My Application, other=false}, {id=2, label=Other, other=false}], questionKey=}
all choices: {id=1, label=My Application, other=false}, {id=2, label=Other, other=false}
first choice: {id=1, label=My Application, other=false}
all of it: My Application
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, now I think I am following: you are trying to dynamically change which question from ProForma is accessed, based on a variable.
If so, that cannot work the way you have tried it as the rule would need to dynamically interpret the smart value. Instead you may either try:
The first way may be easier to understand for maintenance and second way can handle a dynamic number of questions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy wow I think you've done it! I wasn't ware of the new Lookup Table feature! I think this will meet my needs.
Thanks so much Bill! I really appreciate it!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
[Resolved] Hi - I'm unable to crack this error, and would appreciate any help/guidance for the fix:
Audit Log view:
Thanks & Regards,
Dyyan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If I may jump in here @Dyyan
👀 By the look of the logged error message and the content on the screenshots, aren't you missing one {{/}} in the end (closing of {{#lookupIssues}} smart value)? So basically, just add this string before the "thanks" text.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ah, my bad. Thanks so much, @Tomislav Tobijas _Koios_ !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Did anyone manage to get variables to work inside .get() function?
Specifically, we're looking at something like {{lookupObjects.get({{var}})}} where var is the variable.
We've tried all kinds of combinations (with/without quotation marks) but nothing worked.
If this still isn't supported, is there any chance there is some workaround for it?
Cheers,
Tom
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There are now at least two versions of get():
One possible work-around (that I have not tried recently) is:
It may be possible to do this in just two actions; again, I have not tried that.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Cheers @Bill Sheboy !
I've created a string with a combination of indexes and lookup results - this is actually really cool. Now we just need to create an expression (by using Java pattern) but as we're a bit overbooked I'll leave that for the second phase of integration.
If I manage to build something interesting (or within just two actions), I'll share it here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We couldn't use variables inside .match(), then we just use .replace() before and after the use of .match() because replace accepts variables as input.
i.e.:
Using the field description = "a@a.com,b@b.com,2@a.com,c@c.com"
Automation:
Results:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I believe created variables can be used inside the match() function. The trick is to leave off the outer quotation marks and to let the function assume them around the variable representing the regular expression.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you provide an example of what this looks like? Currently trying to use .match on a webhookresponse body and we need to use variables in the regex.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @hessor -- Welcome to the Atlassian Community!
Which version of Jira are you using? This technique works for Jira Cloud as it has the Create Variable action.
Here is a simple example, searching for the issue summary in a response message.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh okay. We have Jira Server so I don't think this would help. Is there any work arounds on Jira Server? We have tried the issue entity property fix but I think that might have also been for Jira Cloud.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am not using Jira Server, and so cannot test if the match() function will accept a parameter of a smart value.
Before proceeding, I recommend a quick test rule with an example Jira issue: use the Summary as a parameter to search in the Description with match(). If that works, you could try either using a custom field or entity property to hold your search expression.
If it does not work, there may not be a way to do this inside of Server's rules yet.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just checked and did not find a suggestion for this in the public backlog, and so you may want to add one:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.