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

Hi Alex,

Sorry again, the raw html editor did it wrong so I copy/paste directly as is the JS code:

// 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);


Regards

J-Serge