Skip to main content
tejashriw155148
Level 4
Nov 25, 2019 1:59 PM UTC
Solved

Fetch enum label instead of value from schema

Hi,

When I use querydef on deliveryStatus field from nms:broadLog schema, It returns values like 0,1,2,.. instead of label like Ignored, Sent, Failed.

Also tried below logic but its not working.

Please let me know how to fetch enum label from schema.

Regards,

Tejashri

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Manoj_Kumar
Manoj_KumarAccepted solution
Community Advisor
Nov 26, 2019 3:59 PM UTC

Hello Tejashri,

The values in enumeration are numeric only. You can refer to the image below to get the exact status.

And in the java-script you can do something like this.

if(enumValue.@label=='1'){
var deliveryStatus='sent';
}

if(enumValue.@label=='2'){

var deliveryStatus='failed';

}

and so on.

Then you can use the deliveryStatus variable where ever you want to use to get the label.

Thanks

Manoj  | https://themartech.pro

7 replies

Manoj_Kumar
Community Advisor
Manoj_KumarCommunity AdvisorAccepted solution
Community Advisor
Nov 26, 2019 3:59 PM UTC

Hello Tejashri,

The values in enumeration are numeric only. You can refer to the image below to get the exact status.

And in the java-script you can do something like this.

if(enumValue.@label=='1'){
var deliveryStatus='sent';
}

if(enumValue.@label=='2'){

var deliveryStatus='failed';

}

and so on.

Then you can use the deliveryStatus variable where ever you want to use to get the label.

Thanks

Translate
Manoj  | https://themartech.pro
tejashriw155148
Level 4
Nov 27, 2019 7:20 AM UTC

Hi,

Could you please let me know where should I add above code to get enum value from deliveryLog.

Regards,

Tejashri

Translate
Manoj_Kumar
Community Advisor
Community Advisor
Nov 27, 2019 7:37 AM UTC

Hello Tejashri,

This is how your updated code will look like.

for each(var enumValue in enumElt.enumValue){

        if(enumValue.@label=='1'){

               var deliveryStatus='sent';

        }

        if(enumValue.@label=='2'){

              var deliveryStatus='failed';

        }

}

Thanks,

Manoj

Translate
Manoj  | https://themartech.pro
tejashriw155148
Level 4
Nov 27, 2019 8:38 AM UTC

Hi,

I tried below code and getting result as:

Delivery Status is: undefined

Noticed that for loop is not working. Could you please check?

Thanks,

Tejashri

Translate
Manoj_Kumar
Community Advisor
Community Advisor
Nov 27, 2019 9:23 AM UTC

Add this code on line no #3

var deliveryStatus="";

Translate
Manoj  | https://themartech.pro
tejashriw155148
Level 4
Nov 27, 2019 12:46 PM UTC

Hi,

Added var deliveryStatus=""; in code, but getting blank value.

yet For loop not working.

could you please give me other solution to display enum label?

Regards,

Tejashri

Translate
pierrec70731455
Level 4
Dec 5, 2019 10:20 AM UTC

Hi,

Here is an alternative solution with analyze="true" and the variable @<my_enum_var>Label :

// vars.targetSchema = default variable generated by the previous Query activity in a workflow temp:queryExportDriveStatus

var schemaName = vars.targetSchema.substr(vars.targetSchema.indexOf(":")+1);

logInfo(schemaName);

var xml =

  <queryDef schema={vars.targetSchema} operation="select" startLine={vars.count} lineCount={vars.batchSize}>

    <select>

      <node expr="@date"/>

      <node expr="@driveStatus" analyze="true"/>

      <node expr="@accountID"/>

      <node expr="@id"/>

    </select>

  </queryDef>;

var query = xtk.queryDef.create(xml);

var res = query.ExecuteQuery()[schemaName];//.queryExportDriveStatus;

var stati = '[';

for each(var status in res){

  stati += '{"account_id":' + status.@accountID + ',"drive_status":"' + status.@driveStatusLabel + '","status_date":"' + formatDate(status.@date, "%4Y%2M%2D") + '","drive_status_id":' + status.@id + ',"topicName":"prod_ingest_adobe_drive_status"},';

}

stati = stati.replace(/,\s*$/, "")+']';

logInfo("STATI : " + stati);

Translate