Compare Handlebar Help!

I am trying to compare a field (record.Form.Id) to a specific set of numbers. If its one of those numbers, its a BrokerageHouse, else NonBrokerageHouse. I'm struggling to get the syntax right since there are a fair amount of comparisons, and any help is greatly appreciated.

{{#if (or 
    (compare record.Form.Id '===' '314')
    (compare record.Form.Id '===' '254')
    (compare record.Form.Id '===' '253')
    (compare record.Form.Id '===' '278')
    (compare record.Form.Id '===' '277')
    (compare record.Form.Id '===' '336')
    (compare record.Form.Id '===' '334')
    (compare record.Form.Id '===' '257')
    (compare record.Form.Id '===' '256')
    (compare record.Form.Id '===' '267')
    (compare record.Form.Id '===' '268')
    (compare record.Form.Id '===' '275')
    (compare record.Form.Id '===' '274')
    (compare record.Form.Id '===' '318')
    (compare record.Form.Id '===' '288')
    (compare record.Form.Id '===' '287')
    (compare record.Form.Id '===' '237')
    (compare record.Form.Id '===' '240')
    (compare record.Form.Id '===' '272')
    (compare record.Form.Id '===' '271')
)}}
    BrokerageHouse
{{else}}
    NonBrokerageHouse
{{/if}}
0

Comments

3 comments
Date Votes
  • Hey Dave,

    {{#compare record.Form.Id '===' '314'}}BrokerageHouse
    {{else compare record.Form.Id '===' '254'}}BrokerageHouse
    {{else compare record.Form.Id '===' '253'}}BrokerageHouse
    {{else compare record.Form.Id '===' '278'}}BrokerageHouse
    {{else compare record.Form.Id '===' '277'}}BrokerageHouse
    {{else compare record.Form.Id '===' '336'}}BrokerageHouse
    {{else compare record.Form.Id '===' '334'}}BrokerageHouse
    {{else compare record.Form.Id '===' '257'}}BrokerageHouse
    {{else compare record.Form.Id '===' '256'}}BrokerageHouse
    {{else compare record.Form.Id '===' '267'}}BrokerageHouse
    {{else compare record.Form.Id '===' '268'}}BrokerageHouse
    {{else compare record.Form.Id '===' '275'}}BrokerageHouse
    {{else compare record.Form.Id '===' '274'}}BrokerageHouse
    {{else compare record.Form.Id '===' '318'}}BrokerageHouse
    {{else compare record.Form.Id '===' '288'}}BrokerageHouse
    {{else compare record.Form.Id '===' '287'}}BrokerageHouse
    {{else compare record.Form.Id '===' '237'}}BrokerageHouse
    {{else compare record.Form.Id '===' '240'}}BrokerageHouse
    {{else compare record.Form.Id '===' '272'}}BrokerageHouse
    {{else compare record.Form.Id '===' '271'}}
        BrokerageHouse
    {{else}}NonBrokerageHouse
    {{/compare}}

    Note: Use Strict check only if you know the data coming is going to match the data type.

    The structure of data, I assumed is as below:

    {
      "record":{
      "Form":{
      "Id": "123"
    }
    }
    }

    To understand more about Compare with else check out our docs here

    0
  • Hey Dave - 

    You may also want to try the #contains helper...  It acts like a string search when you give it a literal. 

    For example try this in the playground

    Context:

    {
      "id": 125,
      "name": "Bob",
      "age": 33
    }

    Formula:

    {
       {{#contains "123*546*556*125" id}}yes{{else}}no{{/contains}}
    }

    1
  • David Gollom brilliant!

    0

Please sign in to leave a comment.

 

Didn't find what you were looking for?

New post