Forums

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

Do Jira Expressions support JavaScript string methods?

Martin Kay May 11, 2023

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

2 answers

1 vote
Jens Schumacher - Released_so
Community Champion
May 11, 2023

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 

0 votes
Martin Kay May 15, 2023

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)

Martin Kay May 15, 2023

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.

Martin Kay May 15, 2023

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.

Jens Schumacher - Released_so
Community Champion
May 19, 2023

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

Martin Kay May 22, 2023

I  have it working using slice().

Thanks for all your help!

Jens Schumacher - Released_so
Community Champion
May 22, 2023

Great, glad you managed to figure it out @Martin Kay

Suggest an answer

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

Atlassian Community Events