How to format "or" clause in Query?

I have this Javascript and I'm trying to make an OR clause for the where but I cannot figure out the syntax and the manual does not show any OR examples.

query 

.select([…snipped…) // <- specify select columns here 

.where('errorMessage').contains('Some text') 

.or('errorMessage').contains('Some other text')   

.limit(1000);

Best Answer

  • ArborRose
    ArborRose Coach
    Answer ✓

    The .limit() issue may be caused by that query syntax hitting a structural limitation in the framework. There are a few alternate approaches you might try to keep the workflow without creating a new column.

    1. Apply Multiple .where() Clauses

    query
      .select([...]) 
      .where('errorMessage').contains('Some text')
      .where('errorMessage').contains('Some other text')
      .limit(1000);
    

    If this returns no rows, Domo may be interpreting it as a AND not OR.

    2. Filter with a custom function and use .filter()

    const results = await query
      .select([...])  
      .limit(1000);   
    
    const filteredResults = results.filter(row => 
      row.errorMessage.includes('Some text') || 
      row.errorMessage.includes('Some other text')
    );
    

    or

    3. Use .where() in a regular expression to capture conditions. Or create a new calculated field in Domo.

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

Answers

  • pwtm
    pwtm Member
    edited October 30

    Sorry, this got posted in the wrong area by accident. Not sure where to post HTML Bricks questions and there isn't any way to move a topic that I can find.

  • Domo's Javascript may not support .or(). Using the following code, you should be able to get the include to return true if either condition is met….creating an or condition.

    query
    .select([...]) // <- specify select columns here
    .where(row => row.errorMessage.includes('Some text') || row.errorMessage.includes('Some other text'))
    .limit(1000);

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

  • pwtm
    pwtm Member

    Thanks!

    I had to remove the .limit() function to make that work or I get a javascript error. however, it is returning all rows in the table, even if the error message does not include the required text. For testing, I changed || to && and it still returned 100% of rows.

    It seems so weird that it is so difficult to create an OR condition. I've been working on this for a few hours now and it's gotten quite frustrating. I have several HTML tables all filtering based on specific text in the error message. This is the only one I have that requires two different keys. I already have several of these completed and I really didn't want to go back to create a function to assign error types to a new column because that would require a lot of refactoring of the other dashboards. It seems like that might be the most straightforward solution even though it feels so unnecessary.

  • ArborRose
    ArborRose Coach
    Answer ✓

    The .limit() issue may be caused by that query syntax hitting a structural limitation in the framework. There are a few alternate approaches you might try to keep the workflow without creating a new column.

    1. Apply Multiple .where() Clauses

    query
      .select([...]) 
      .where('errorMessage').contains('Some text')
      .where('errorMessage').contains('Some other text')
      .limit(1000);
    

    If this returns no rows, Domo may be interpreting it as a AND not OR.

    2. Filter with a custom function and use .filter()

    const results = await query
      .select([...])  
      .limit(1000);   
    
    const filteredResults = results.filter(row => 
      row.errorMessage.includes('Some text') || 
      row.errorMessage.includes('Some other text')
    );
    

    or

    3. Use .where() in a regular expression to capture conditions. Or create a new calculated field in Domo.

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **