Solved

ifCondition use 'in'

  • 29 February 2024
  • 1 reply
  • 34 views

Badge

Hola buenas, quiero implementar un {{#ifCond custom.value ‘in’ [‘a’, ‘b’, ‘c’]}} true, me podrían indicar como puedo llegar a estó desde una validación de kustomer, gracias

icon

Best answer by derek.parson 1 March 2024, 20:18

View original

1 reply

Badge +3

Hello Felipe,

 

Thank you for creating this question in our community. Public discussions like this help everyone grow and learn more.

 

Regarding your question, if I’m understanding correctly you are needing to check the values of an array of items to see if they are equal to a specific passed in value. If this is the case you can achieve this by combining the {{#each}} helper with the {{#ifCond}} helper as follows if the array equals [‘a’, ‘b’, ‘c’]:

 

{{#each array}}{{#ifCond this ‘===’ custom.value}}true{{/ifCond}}{{/each}}

 

The result will output a string value of true. If you need the boolean type then the above can be done in a Transform Generic step in our workflows then where you need the boolean value added you can use our /#fn:parseBool helper to get the boolean output. To use this helper you would target the output of the Transform Generic step as follows:

 

/#fn:parseBool,steps.{stepIdHere}.output

 

Some additional information here in case it is useful. The each helper will provide an output here each time the condition is correct. So if we have two of the same values in the array the above would output “truetrue” which is not ideal. I’m not sure there is a way to output “true” only once here but we can at least prepare to be able to adjust for this to be in a nicer format in any following steps by adjusting as follows if the array equals [‘a’, ‘b’, ‘b’, ‘c’] and custom.value = ‘b’:

 

{{#each array}}{{#ifCond this ‘===’ custom.value}}{{#if @last}}true{{else}}true, {{/ifCond}}{{/each}}

 

The result will be “true, true” which happens due to adding a comma follow by a space for all instances of the value being found and if at the last value (indicated by @last combined with the #if helper) in the array only output the string true instead of “true, “.

 

I hope this helps and if you have any further questions please share them here!

 

Cheers,

Derek Parson

Sr. Technical Support Engineer

Reply