0

I need to use a cfoutput in a cfset tag to get multiple line items to send in xml. I know it's wrong to put a CF tag into another, but I'm looking for the best way to do this. Thanks in advance.

<cfset soapBody = soapBody & "
    <cfoutput query="getitems">                        
    <item id=""#id#"">
        <unitPrice>#getitems.unitprice#</unitPrice>
        <quantity>#getitems.quantity#</quantity>
        <productname>#getitems.productname#</productname>
        <taxAmount>#getitems.taxamount#</taxAmount>
        <unitOfMeasure>#getitems.unitofmeasure#</unitOfMeasure>
        <taxRate>#getitems.taxrate#</taxRate>
        <totalAmount>#getitems.totalamount#</totalAmount>
        <grossNetIndicator>#getitems.grossnetindicator#</grossNetIndicator>
    </item>
    </cfoutput>         
">
rrk
  • 15,677
  • 4
  • 29
  • 45
Unohoo
  • 27
  • 1
  • 6

1 Answers1

2

You can use <cfsavecontent> tag for this. It is very use full the cases you are trying to create a big piece of string dynamically.

<cfsavecontent variable="soapBody">
    <cfoutput>#soapBody#</cfoutput>
    <cfoutput query="getitems">                        
    <item id=""#id#"">
        <unitPrice>#getitems.unitprice#</unitPrice>
        <quantity>#getitems.quantity#</quantity>
        <productname>#getitems.productname#</productname>
        <taxAmount>#getitems.taxamount#</taxAmount>
        <unitOfMeasure>#getitems.unitofmeasure#</unitOfMeasure>
        <taxRate>#getitems.taxrate#</taxRate>
        <totalAmount>#getitems.totalamount#</totalAmount>
        <grossNetIndicator>#getitems.grossnetindicator#</grossNetIndicator>
    </item>
    </cfoutput>         
</cfsavecontent>
rrk
  • 15,677
  • 4
  • 29
  • 45
  • I was able to generate the XML, but every time I try to include it in the API I get a Parse Error. – Unohoo Jul 17 '20 at 14:51