Solved

Select a list of values in JQL

  • 14 March 2019
  • 1 reply
  • 804 views

Badge

I have a question regarding filtering multiple values in JQL. I have the following JQL


function main() {

return join(

Events({

from_date: '2019-01-01',

to_date: '2019-01-24',

event_selectors:[{event:'event'}]

}),People(),

{

type: 'left',

selectors: [

{

//selector: '(user["Id"] == 100)'

selector: '(user["Id"] in [100,101,102])'

}

]

})

.filter(tuple => tuple.event && tuple.user)


The highlighted code doesn’t work. I can use selector: '(user["Id"] == 100 or user["Id"] == 101 or user["Id"] == 102)' but I have a very long list. Is there a simple way to do it?



icon

Best answer by evanmoss 9 April 2019, 01:09

View original

1 reply

Badge +1

Hi Mixjet,


There's not really a great way to do this besides pasting the list into your query, then using it to create the string. For example:


var users = ['abc', 'def', 'ghi'];
var selectorStr = '(';
_.each(users, function(user, index) {
  selectorStr += 'user["Id"] == ' + user;
  if (index == users.length - 1)
    selectorStr += ')';
  else
    selectorStr += ' or ';
});


You can also use the same user array, skip using the selector, and change your filter to

.filter(tuple => tuple.event && tuple.user && _.contains(users, tuple.user.properties.Id))


One more thing is if you change your join type to "inner", you won't need to filter for tuple.event or tuple.user, you can just do

.filter(tuple => _.contains(users, tuple.user.properties.Id))


Hope that helps!


Thanks,

Evan


Reply