Different results from search query in workflow and web UI

Good morning! I tried many variations of the workflow and search API but I'm getting the same result, so here I am.

I'm creating a workflow that needs to search for past issues, using a direct String query (not obj with extended properties). 

The query is pretty simple

State: {Done} resolved date: 2024-11-05 .. 2025-11-05 project: PROJECTNAME summary: SUMMARYVALUE

and works perfectly fine in the Issue search from the web browser. However, when the workflow is triggered, I'm always getting 0 results. Things I tried:

  • var results = search.search(issue.project, query, ctx.currentUser);
  • var results = search.search(null, query, ctx.currentUser);
  • var results = search.search(issue.project, query);
  • var results = search.search(null, query, null);
  • removing the `project: PROJECTNAME` part from the query

What could cause this difference? How could I better debug it? (current workflow: console.log, save, create a test issue, repeat)

Also, but not directly related:

  • `issue.tags` is always an empty list. Are they assigned later? Is this documented anywhere I'm not finding? (the workflow has the guard `ctx.issue.becomesReported`: if it's the case they are assigned asynchronously, what the guard should be?)
  • is the `search` object supporting advanced searches? I'm trying to use grouping with parenthesis, but seems not to be working

Thanks!

0
3 comments

Hi Luca!

The first thing I'd recommend making sure of is that you declare the search module in the beginning of your workflow code like so:

const search = require('@jetbrains/youtrack-scripting-api/search');

Regarding your questions:

State: {Done} resolved date: 2024-11-05 .. 2025-11-05 project: PROJECTNAME summary: SUMMARYVALUE

Perhaps the user triggering the workflow (ctx.currentUser) doesn't have access to issues that should be returned by this search, which would explain the 0 results. Note also that results are returned in the Set object. See Working with Set Objects.

`issue.tags` is always an empty list. Are they assigned later?

If the tags had been assigned to the draft before the issue was created from that draft, ctx.issue.tags should return a set object with these tags. So these tags may have been added later and not to the draft.

is the `search` object supporting advanced searches? I'm trying to use grouping with parenthesis, but seems not to be working

The search method is expected to support any queries that you can make in the UI or via REST API.

As we may need to ask you to share the actual code for further troubleshooting, I suggest submitting a private ticket if you have more questions: https://jb.gg/ytsup.

0

Hi Stanislav Dubin !

Thanks for the answer!

Perhaps the user triggering the workflow (ctx.currentUser) doesn't have access to issues that should be returned by this search

the user triggering the workflow (e.g. mine) has indeed the permission (it is working in the UI) so I don't think it's the problem. The code itself is not secret but I'll follow your advice and share it in private, and report here if the solution is interesting for the general public.

Thanks!

0

For anyone coming here in the future: thanks to Stanislav Dubin hints I could see some things I was getting wrong:

  • main issue is I was using `Array.from` to try cohercing search results, tags etc. to be Array and then apply map/filter functions. A wise use of `forEach` as shown me by a simple working example fixed the issue
  • I was confused by printing via console.log or JSON.stringify objects after this conversion, due to silent failures (javascript issues)

Thanks again for the help!

1

Please sign in to leave a comment.