How to automatically retrieve project id or key in custom JQL function for versions

Hi everyone,

I’m reaching out to seek some support regarding an issue we’re facing with our custom JQL function. We’re trying to find a way to retrieve the project ID or key automatically when the custom JQL function is triggered. As of now, the only solution we’ve come across is to pass the project ID or key as an argument within the JQL function, which we believe is not ideal for our users. It seems redundant, especially since the project is already specified at the beginning of the JQL query. For example:

project = "TEST" and fixVersion in customJQLFunction("TEST", "1.0.0")

Here are our manifest.yml file and the arguments that our JQL function currently receives:

image

As you can see, there’s no project-specific information included. Does anyone know how we can resolve this? Is this a bug, a limitation, or is there another approach we might be missing?

Thanks in advance for any insights or suggestions!

3 Likes

Hi @FaikBurakTredi, thank you for reaching out!

The behavior you described is by design - the only way to get additional information within your function is to pass it as an argument. I can understand that, in your case, it might feel redundant to pass the project key again while it is already available in a JQL query. However, during the JQL query processing, we extract and analyze the function clause: fixVersion in customJQLFunction("TEST," "1.0.0"), and later, the precomputation is saved for this unique function clause (and its arguments list).

It is described in detail in our documentation:
https://developer.atlassian.com/cloud/jira/platform/jql-functions/#high-level-overview

Let’s imagine that, in your case, we don’t pass the project key as an argument. Only a single precomputation will be stored for your function clause: fixVersion in customJQLFunction("1.0.0"). At the same time, our end-user may execute several JQL queries with different project keys:

  • project = "TEST" and fixVersion in customJQLFunction("1.0.0")
  • project = "NEW PROJECT" and fixVersion in customJQLFunction("1.0.0")

In such a scenario, the second query will use the existing precomputation and return incorrect results. It is also possible to execute the query without the first condition: fixVersion in customJQLFunction("1.0.0"), which doesn’t have any information about the project but will still use the existing precomputation and return incorrect results.

To summarize, passing the proper list of arguments is important in the context of storing precomputations and returning correct results. Especially if your function depends on the context parameters.

Best regards,
Łukasz

1 Like