use of "if" in XML Write task

Post any question you may have in regards to GoAnywhere Director and let our talented support staff and other users assist you.

use of "if" in XML Write task

Postby SeanC » Wed Oct 16, 2013 2:24 pm

I'm using the XML Write task to generate an xml document from a rowset retrieved from a database query. There are elements that I want to appear in my output only if certain conditions are met. I would like to use an "if" inside the xml write prior to generating the element, but it seems to operate differently when inside the xml write than under normal project flow. Namely, it has a "test" attribute as opposed to the usual "condition" attribute and for the life of me I can't figure out what it wants in that test attribute. For example, my code goes something like this:

Code: Select all
      <xmlWrite outputFile="${system.job.workspace}/output.xml" defaultTrim="right" outputFileVariable="OutputFile" version="1.0">
         <header>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;</header>
         <element name="vendors">
            <attribute name="xmlns" value="http://www.stryker.com/party" />
            <forEach inputRowSetVariable="${ResultSet}">
               <element name="vendor">
                  <element name="name" value="${ResultSet[Supplier_Name]}" />
                  <element name="directFlag" value="${ResultSet[Direct_Flag]}" />
                  <element name="activeStatus" value="${ResultSet[Active_Status_MW]}" />
               </element>
            </forEach>
         </element>
      </xmlWrite>


I would like to have the element "directFlag" only appear in the output if its value is "true". When I try adding that I get an error:

[8003 - xmlWrite] Invalid value '${ResultSet[Direct_Flag] == 'true'}' for attribute 'test' in element 'if'

here's the code:

Code: Select all
      <xmlWrite outputFile="${system.job.workspace}/output.xml" defaultTrim="right" outputFileVariable="OutputFile" version="1.0">
         <header>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;</header>
         <element name="vendors">
            <attribute name="xmlns" value="http://www.stryker.com/party" />
            <forEach inputRowSetVariable="${ResultSet}">
               <element name="vendor">
                  <element name="name" value="${ResultSet[Supplier_Name]}" />
                  <if test="${ResultSet[Direct_Flag] == &apos;true&apos;}">
                     <element name="directFlag" value="${ResultSet[Direct_Flag]}" />
                  </if>
                  <element name="activeStatus" value="${ResultSet[Active_Status_MW]}" />
               </element>
            </forEach>
         </element>
      </xmlWrite>


I've tried lots of different values for the test clause but nothing seems to work, including simply entering "${true}". Can someone explain how this is used?

Thanks!

Sean
SeanC
 
Posts: 5
Joined: Tue Feb 28, 2012 1:52 am

Re: use of "if" in XML Write task

Postby Support_Rick » Thu Oct 17, 2013 5:03 pm

Sean,

The XML If Condition was originally designed for Header/Detail relationships. Like the following:

Code: Select all
<forEach inputRowSetVariable="${details}">
   <if test="${details[&quot;TDPON&quot;]} eq ${headers[&quot;THPON&quot;]}">
      <element name="DocShpLineItem">
         <attribute name="ContainerQuantity" value="${details[&quot;TDCONQTY&quot;]}" />
         <attribute name="CommodityCode" value="${details[&quot;TDCOMCDE&quot;]}" />
         <attribute name="SKUNumber" value="${details[&quot;TDITM&quot;]}" />
         <attribute name="Description" value="${details[&quot;TDDES&quot;]}" />
      </element>
   </if>
</forEach>


Conditional Element statements are being considered for a future release.
Rick Elliott
Sr. Product Specialist
(402) 944.4242
(800) 949-4696
Support_Rick
Support Specialist
 
Posts: 107
Joined: Tue Jul 17, 2012 2:12 pm

Re: use of "if" in XML Write task

Postby SeanC » Thu Oct 17, 2013 7:58 pm

Ok. Thank you for the follow-up. I think I can find some other ways to work around this in the source query.
SeanC
 
Posts: 5
Joined: Tue Feb 28, 2012 1:52 am


Return to Community Forum

Who is online

Users browsing this forum: No registered users and 1 guest

cron