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.