Migs
Migs

Reputation: 1480

Otherwise in Oracle BI Publisher not Working

I have the following XML structure from My Data Set:

<DATA_DS>
<G_1>
<INVOICE_NUMBER>20005</INVOICE_NUMBER>
<BATCH_SOURCE_NAME>MIGRATION</BATCH_SOURCE_NAME>
<CT_REFERENCE/>
</G_1>
<G_1>
<INVOICE_NUMBER>454162</INVOICE_NUMBER>
<BATCH_SOURCE_NAME>FM Source Number</BATCH_SOURCE_NAME>
<CT_REFERENCE>454162</CT_REFERENCE>
</G_1>
<G_1>
<INVOICE_NUMBER>455920</INVOICE_NUMBER>
<BATCH_SOURCE_NAME>FM Source Number</BATCH_SOURCE_NAME>
<CT_REFERENCE>455920</CT_REFERENCE>
</G_1>
</DATA_DS>

I have put the following logic in my RTF Template inside a FOR-EACH in a Table:

<?choose:?>
<?when://BATCH_SOURCE_NAME='FreightMaster'?><?CT_REFERENCE?><?end when?>
<?when://BATCH_SOURCE_NAME='FreightMaster-deactivated'?><?CT_REFERENCE?><?end when?>
<?when://BATCH_SOURCE_NAME='FM Source Number'?><?CT_REFERENCE?><?end when?>
<?otherwise:?><?INVOICE_NUMBER?><?end otherwise?>
<?end choose?>

However, my data isn't coming up correctly. It's showing as:

Invoice Number
-----------------
<null>
454162
455920

It was supposed to be like below:

Invoice Number
-----------------
20005
454162
455920

When I try to define MIGRATION as an option, it works:

<?choose:?>
<?when://BATCH_SOURCE_NAME='MIGRATION'?><?INVOICE_NUMBER?><?end when?>
<?when://BATCH_SOURCE_NAME='FreightMaster'?><?CT_REFERENCE?><?end when?>
<?when://BATCH_SOURCE_NAME='FreightMaster-deactivated'?><?CT_REFERENCE?><?end when?>
<?when://BATCH_SOURCE_NAME='FM Source Number'?><?CT_REFERENCE?><?end when?>
<?otherwise:?><?INVOICE_NUMBER?><?end otherwise?>
<?end choose?>  

The actual output matches the expected output:

Invoice Number
-----------------
20005
454162
455920

I know i can just specify the Source Names in the WHEN clause, but there are over 20 Source Names and I'd like to simplify the code.

Any idea why it isn't working?

Upvotes: 0

Views: 951

Answers (1)

Based
Based

Reputation: 970

<?choose:?>
   <?when:BATCH_SOURCE_NAME='FreightMaster'?><?CT_REFERENCE?><?end when?>
   <?when:BATCH_SOURCE_NAME='FreightMaster-deactivated'?><?CT_REFERENCE?><?end when?>
   <?when:BATCH_SOURCE_NAME='FM Source Number'?><?CT_REFERENCE?><?end when?>
   <?otherwise:?><?INVOICE_NUMBER?><?end otherwise?>
<?end choose?>

Check XPath reference

Eventhough you are doing a for-each loop, // will navigate to the root and then just select all BATCH_SOURCE_NAME elements.

//BATCH_SOURCE_NAME='FreightMaster' is always true for your data because a row exists where BATCH_SOURCE_NAME='FreightMaster', so <?CT_REFERENCE?> is printed, which is null for the first row.

In the second case BATCH_SOURCE_NAME='MIGRATION' is always true for the same reason, so now you print INVOICE_NUMBER for every row. The result is correct because INVOICE_NUMBER is the same as CT_REFERENCE for rows 2 and 3.

Upvotes: 1

Related Questions