I am using server side javascript to generate our recipient emails. I would like to be able to output different code if the asset_type_code is form_question_type_file_upload. I have a conditional if/else but it does not work. Is there any obvious reasons why this will not work? Thanks
var assetIDs = %globals_asset_children_link_type_2:221324^as_asset:asset_children_link_type_2,asset_type_code^empty:[]%;
if (assetIDs.length > 0) {
assetIDs.forEach(function(assetID) {
if (assetID.asset_type_code === "form_section") {
assetID.asset_children_link_type_2.forEach(function(asset) {
let typecode = `%globals_asset_type_code:${asset}%`;
var asset = asset.replace(':','_');
if (typecode === "form_question_type_file_upload") {
print(`<p style="-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;font-size:14px;line-height:25px;font-weight:400;mso-hide:% response_${asset}_file_size^empty:all%;display:% response_${asset}_file_size^empty:none%;">% question_name_${asset}%: % response_${asset}%</p>`);
} else {
print(`<p style="-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;font-size:14px;line-height:25px;font-weight:400;mso-hide:% response_${asset}^empty:all%;display:% response_${asset}^empty:none%;">% question_name_${asset}%: % response_${asset}%</p>`);
}
});
}
});
}
You can’t evaluate keywords during SSJS execution. Picture your code going through three distinct phases:
Complete keywords are processed - in your example that would only be the one on the first line
Then the JavaScript is executed
Then the output of the SSJS print statements is processed for keywords
Any keyword results you want to do logic on, such as lines 6-8, must be completely evaluated before the SSJS runs. When your code runes line8, the value of typecode is “%globals_asset_type_code:12345%”, not the result of that keyword.
I’m not sure you can pull child and grandchild assets into a variable with a single keyword, you may need to use an asset listing.