Keyword Execution Order in SSJS


(Mark Graham) #1

Hi All,

I’m having some issues trying to work out why the following keyword isn’t evaluating properly;

%globals_asset_contents_raw:313081^run_ssjs^with_get:rootNodes={asset_metadata_assetIds}%

Background:
I have an asset listing that generates a json object of events. I’m wanting to pass that asset listing a dynamic root node(s) from a content container template.

globals_asset_contents_raw:313081 refers to our asset listing, which we want the SSJS to be processed on.
asset_metadata_assetIds is a related asset metadata field on the content container that will have the assetids that we want to be root nodes.

The issue is that when the page gets loaded, the asset listing isn’t getting the ids, it’s getting the un-evaluated keyword of {asset_metadata_assetIds}. The error is as follows in the log manager;

Any ideas or what I’m doing wrong, or perhaps where I could look to fix it?
Thanks in advance,
Mark


(John gill) #2

The issue is that by the time %globals_asset keywords are evaluated the %asset_ context will have changed and will no longer refer to the content container (it may refer to to %frontend_asset, or maybe refer to nothing, I’m not sure).

You either need a way to evaluate the asset_metadata_assetIds immediately, and then use that later when globals_asset is processed (probably SSJS?), or you need a way to force the %globals_asset_contents_raw to evaluate immediately “inside” the content container.

I think there is a trick around using an empty param for this latter purpose, something like

%globals_get_fake^append:313081^as_asset^asset_contents_raw^run_ssjs^with_get...

but no guarantee that a chain of modifiers that long will work :thinking: (I’m not sure what the limit on modifier chaning is, but there seems to be one).


(Tom Stringer) #3

Mark, have you tried printing it from within a ssjs script tag?

Something like:

<script runat="server">print('%' + 'globals_asset_contents_raw:313081^with_get:rootNodes=' + %asset_metadata_assetIds% + '%');</script>

See: Problems with keyword replacement values as modifiers

Not sure if that’ll do the trick…


(Mark Graham) #4

Thanks for your suggestions, it definitely gave me some food for thought.

I ended up abandoning my initial idea of filtering my assets at the asset-listing level and instead just used some SSJS to do it for us. Not the most ideal solution, but it gets the job done.