Comparing apples with apples in Jira expressions

My Jira expression is failing because I’m trying to compare an issue type id, which is a Number in the expression context, with a list of issue type ids that I’ve stored as Strings in a project entity property. Here is my Jira expression:

project.properties['issue-type-ids'].includes(issue.issueType.id)

The project.properties['issue-type-ids'] is a list of String, but the issue.issueType.id is a Number.

Is there a way to cast one or other side of the comparison so that it compares ‘apples with apples’?

References:

The IssueType returned by Jira expressions has a Number id.

The IssueTypeDetails returned by the Jira API has a String id.

In Jira Server, the IssueType interface has this method: String getId();, so Strings rule there too.

Answering my own question. The trick is to cast the elements of the list to Number, like this:

project.properties['issue-type-ids'].map(Number).includes(issue.issueType.id)

It’s unfortunate that this casting is required at all. I would much prefer the Jira Expression type IssueType to return id values as Strings, consistent with the Jira Server representation and the Jira REST API representation.

Aside: you can create Numbers from Strings, but not the other way around, I believe.

5 Likes

Thanks for posting this @david.pinn :slight_smile:

To create a String from Number, you can just concatenate it with an empty string (1 + "" == "1").

I agree that IDs should be returned as Strings rather than Numbers, which would be not only consistent with Jira Server (which is less important), but also with the Jira Cloud REST API. Unfortunately, this would be hard to change now as it could break existing expressions.

That’s a good tip. Thanks for that.