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.
3 posts Page 1 of 1

SeanC

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

Post by 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><?xml version="1.0" encoding="UTF-8" ?></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><?xml version="1.0" encoding="UTF-8" ?></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

Support_Rick

Support Specialist
Posts: 592
Joined: Tue Jul 17, 2012 2:12 pm
Location: Phoenix, AZ

Post by 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["TDPON"]} eq ${headers["THPON"]}">
		<element name="DocShpLineItem">
			<attribute name="ContainerQuantity" value="${details["TDCONQTY"]}" />
			<attribute name="CommodityCode" value="${details["TDCOMCDE"]}" />
			<attribute name="SKUNumber" value="${details["TDITM"]}" />
			<attribute name="Description" value="${details["TDDES"]}" />
		</element>
	</if>
</forEach>
Conditional Element statements are being considered for a future release.
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696

SeanC

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

Post by 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.
3 posts Page 1 of 1