Get Enumerations in JavaScript

Avatar

Avatar

alexanderh76698

Avatar

alexanderh76698

alexanderh76698

04-08-2017

Hello everyone,

I currently try to get enumerations list in a javascript object.

I wasn't able to find a standarf function in the JS API of campaign, so I fetch all the values using xtkQueryDef.

The return of my query is this:

<enumValue-collection>   <enumValue label="4305615529813"/>   <enumValue label="4305615440668"/> </enumValue-collection>

When I try to parse the XML to get the child nodes (<enumValue>) that actually contain the values I need, I face the issue that it doesn't recognize the hyphen in the parent node. The error message tells me that "collection" isn't defined (it cuts the string at the hyphen).

04.08.2017 13:15:48    js    JST-310000 Fehler bei der Auswertung des Scripts 'rosImportProducts/js' Zeile 40: collection is not defined.

This is what I try:

for(var ean in availProductsRes.enumValue-collection)

  logInfo(availProductsRes.enumValue-collection[ean].@label);

Is there a better way of fetching an enumation list in JS?

Or is this issue (hypen in XML node name) already known at Adobe?

Best regards

Alex

View Entire Topic

Avatar

Avatar

Jean-Serge_Biro

MVP

Avatar

Jean-Serge_Biro

MVP

Jean-Serge_Biro
MVP

21-08-2017

Hello Alex,

Sorry for answering a bit late.

I am sure that I confused you a bit with my previous post, sorry in advance.
Actually, when you proceed inside a workflow JS activity, the collection is directly named as the schema parameter part without the space name.
It is in webApp and report that XML element is added with -collection.

Please may you execute this code in a Javascript activity in a workflow, you should get the right values of the itemized list given in parameter:

// itemized list (énumération in French) for a database enum (xtk:enum)

var enumId = "576797577"; // webAppNature itemized list (check your value in your own instance)

var queryXtkEnumValue = xtk.queryDef.create(

    <queryDef schema="xtk:enumValue" operation="select">

      <select>

        <node expr="@label"/>

      </select>

      <where>

        <condition expr={"[@enum-id]=" + enumId} />

      </where>

    </queryDef>)

try

{

  var resXtkEnumValue = queryXtkEnumValue.ExecuteQuery();

  logInfo("[WKF337] get the values enumValue of the itemized list id = " + enumId + " (xtk:enum)");

  logInfo("[WKF337] Count of values = " + resXtkEnumValue.child('enumValue').length());

}

catch(e)

{

  logWarning("[WKF337] Error in getting the values enumValue of the itemized list id=" + enumId + " (xtk:enum)");

  logError("[WKF337] Error number: " + e); // or use logWarning the treatment must go on despite this error

}

for each(var value in resXtkEnumValue.enumValue) // there is no['enumValue-collection'] node in workflow (as there are in webApp and report)

  logInfo("[WKF337] value = " + value.@label);

for each(var value in resXtkEnumValue.enumValue) // there is no['enumValue-collection'] node in workflow (as there are in webApp and report)

  logInfo("[WKF337] value = " + value.@label);

You should get this result in the log trace:

1283081_pastedImage_1.png

Moreover, if you don't need complex queries (or some specific queries as dynamic IN parameter), whatever being in workflow/webApp/report, you can use Query activity instead.

Best Regards.
Jean-Serge