Hi there,
I need to output “T” if any of the following conditions are met. Currently, it outputs TTT if the 3 conditions are met, instead of a single “T”. I’ve tried a number of things with no success. Wondering if someone had to do something similar. I’m iterating through the Shopify Line Items Properties. Thanks!
{{#each line_items}}
{{#each properties}}
{{#compare name “==” “Preferred Name”}}
T
{{else}}
{{#compare name “==” “Nickname”}}
T
{{else}}
{{#compare name “==” “Full Student Name”}}
T
{{/compare}}
{{/compare}}
{{/compare}}
{{/each}}
{{/each}}
Are you trying to map to a line level field or a header level field? If line level, then you can do this:
{{#each line_items}}
{{#contains (pluck properties "name") "Nickname"}}T{{else contains (pluck properties "name") "Full Student Name"}}T{{else contains (pluck properties "name") "Preferred Name"}}T{{else}}F{{/contains}}
{{/each}}
If you're trying to map to the header level, I can't think of anyway to do it.
Hi Tyler,
Appreciate your response. I’m trying to map to the line level.
Data sample is:
"line_items": [
{
properties": [
{
"name": "Preferred Name",
"value": "abc"
},
{
"name": "Nickname",
"value": "def"
},
etc ...
]
}]
I tried using the above and I got:
Message: Could not compile handle bar "{{#each line_items}} {{#each properties}} {{#contains (pluck properties "name") "Nickname"}}T{{else contains (pluck properties "name") "Full Student Name"}}T{{else contains (pluck properties "name") "Preferred Name"}}T{{else}}F{{/contains}} {{/each}} {{/each}}" because "Missing helper: "pluck"" .Please correct and retry.
I’ve had the same error using other helpers.
Thanks
Let me check internally. I'm guessing these new handlebars may not work with NetSuite or at least NetSuite imports using SuiteBundle.
Can you try the above for an actual run? It may just be an issue with preview and not an issue at runtime.
Hi Tyler, in the end I resolved it using:
{{#compare (regexSearch (jsonSerialize line_items) "\\"name\\":\\"Preferred Name\\"|\\"name\\":\\"Nickname\\"|\\"name\\":\\"Full Student Name\\"") "!=" "-1"}}T{{/compare}}
and it works in Preview returning T only once.
Ah, that's a great solution.