You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Do Jira Expressions used in workflow conditions support the full set of JavaScript string methods?
Specifically, I'm trying to use:
issue.customfield_xxxxx.startsWith("some text")
If this is not supported, is there an alternative way to do this?
Thanks,
Martin Kay
Hi @Martin Kay
Jira Expressions support a subset of JavaScript string methods, but not the full set. Unfortunately, startsWith() is not one of the supported methods. However, there are a couple alternative ways to achieve the same result.
You can use the matches operator with a regular expression to match the beginning of the string. Here's an example:
issue.customfield_xxxxx matches "^some text.*"
Another option is to use the indexOf() method to check if a string starts with a certain value. For example, the following expression will return true if the value of the customfield_xxxxx field starts with the text "some text":
issue.customfield_xxxxx.indexOf("some text") === 0
The reference documentation lists all available methods and properties for strings.
Cheers,
Jens
I tried using both of the above suggestions, but neither one worked.
The condition should return True if the custom field does NOT start with the default text string "*** Enter test plan here ***" and is not empty. When tested, these conditions never return True.
Here is the indexOf condition:
(!(issue.customfield_10043.indexOf("*** Enter test plan here ***")===0)) && (issue.customfield_10043.length > 0)
Here is the matches (regular expression) condition:
(!(issue.customfield_10043 matches "^*** Enter test plan here ***.*")) && (issue.customfield_10043.length > 0)
For the moment, the closest condition I've been able to get to work is using the include() method, which checks for the default text anywhere in the custom field value:
(!issue.customfield_10043.includes("*** Enter test plan here ***")) && (issue.customfield_10043.length > 0)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looking at the linked "reference documentation", I see that the match syntax in your example doesn't match the linked documentation. I will try and find a clear example on how to use "match". The documentation does not explain how to use match, what regular expressions are, how to form a regular expression and what the many options are when doing so.
Another omission is that the documentation doesn't explain which string operators are supported in Jira Expressions and list any differences from the Javascript spec, if any.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tested indexOf() more carefully, testing if it can find a single character and found that it does NOT work at all: issue.customfield_10043.indexOf("Q")===3
Edited my custom field in my test issue and placed Q in position 3. The condition evaluated to false. Also tested adjacent positions - just in case.
So I changed my condition to check if slice() works and found that it does for the following condition:
(issue.customfield_10043.length > 0) && (issue.customfield_10043.slice(0, 28) != "*** Enter test plan here ***")
This tests if my custom field has anything in it and if the first 28 characters do not match my default text string.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry about the bad example, it wasn't meant to be literal. Should have made that clearer.
The syntax is based on the JavaScript object. Without having tested it, I would expect it to work the same way. Take a look at the examples for the JavaScript syntax: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match
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.
Great, glad you managed to figure it out @Martin Kay
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.