Matrix Version: 5.4.5.3
I am trying to list link type assets sitting in the folders under the set root node(#123122) in the metadata.
Folder Structure
Keyword stored in variable(assetType) is not evaluating in the if condition.
I can easily retrieve all the required information in childAssets variable if the Link assets are available directly under the root node.
It would be nice if can fetch everything in the grandchildAssets variable instead of asset ids only like childAssets variable.
Can someone advice on how to evaluate the if condition correctly?
<script runat="server">
const childAssets = %asset_metadata_WHS_search_root_id^as_asset:asset_children_link_type_1_2^json_decode^as_asset:asset_name,asset_type_code,asset_type,asset_url,asset_assetid,asset_metadata_WHS_doc_categories,asset_metadata_WHS_doc_title,asset_metadata_WHS_doc_number,asset_metadata_WHS_doc_set_id,asset_metadata_WHS_show_filters^empty:[]%;
const grandChildAssetIds = %asset_metadata_WHS_search_root_id^as_asset:asset_children_link_type_1_2^as_asset:asset_children^json_decode^empty:[]%;
print('<p>' + grandChildAssetIds.length + '</p>');
grandChildAssetIds.forEach(function(assetId){
var assetType, assetDocSetID, assetDocNumber,assetTitle;
for(i=0; i < assetId.length; i++) {
assetTypeCondition ="%globals_asset_type:"+ assetId[i] +"^eq:LinkWWWWW:true:false%";
assetType ="%globals_asset_type:"+ assetId[i] +"%";
assetDocNumber = '%globals_asset_metadata_WHS_doc_number:'+ assetId[i] +'%';
assetTitle = '%globals_asset_metadata_WHS_doc_title:'+ assetId[i] +'%';
assetDocSetID = '%globals_asset_metadata_WHS_doc_set_id:'+ assetId[i] +'%';
print('<p>' + assetType.length + '</p>'); //Output: 28
print('<p>' + assetType + '</p>'); //Output: Link
if(assetTypeCondition) { // Meeting the condition and print the following
print('<p>' + assetType +" - " + assetDocNumber + ' - ' + assetTitle + ' - ' + assetDocSetID + '</p>');
}
if(assetType === "Link") { // Doesn't meet the condition
// above condition is like if(%globals_asset_type:123321%=== "Link")
print('<p>' + assetType +" - " + assetDocNumber + ' - ' + assetTitle + ' - ' + assetDocSetID + '</p>');
}
}
});
</script>