0

I am trying to get the first name from the order confirmation but the field AMPscript returns is empty.

This is my code:

%%[
var @firstName
var @lastName
var @email
var @products
var @subscriberKey

set @xml = OrderAsXML
set @firstName = BuildRowsetFromXml(@xml, '/order/customer/billing-address/first-name', 1)

]%%

<br>
&nbsp;
<table border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%">
  <tr>
   <td style="padding:0 0px; font-family: Arial; font-size: 15px; line-height: 20px; color: #555555;">
     <p style="margin: 0 20px 16px; font-size: 16px; line-height: 1.5; color: #232323; font-family: Arial;">
      %%=v(@firstName)=%% %%=v(@xml)=%% %%OrderAsXML%%
     </p>
    </td>
  </tr>
</table>

XML code:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order order-no="00000301">
    <order-date>2019-06-24T09:35:22.076Z</order-date>
    <created-by>storefront</created-by>
    <original-order-no>00000301</original-order-no>
    <currency>EUR</currency>
    <customer-locale>nl_BE</customer-locale>
    <taxation>gross</taxation>
    <invoice-no>00001501</invoice-no>
    <customer>
        <customer-no>00003001</customer-no>
        <customer-name>X Cleeren</customer-name>
        <customer-email>X</customer-email>
        <billing-address>
            <first-name>X</first-name>
            <last-name>X</last-name>
            <address1>X</address1>
            <address2>X</address2>
            <city>X</city>
            <postal-code>X</postal-code>
            <state-code>undefined</state-code>
            <country-code>X</country-code>
            <phone>X</phone>
        </billing-address>
    </customer>
    <status>
        <order-status>NEW</order-status>
        <shipping-status>NOT_SHIPPED</shipping-status>
        <confirmation-status>CONFIRMED</confirmation-status>
        <payment-status>NOT_PAID</payment-status>
    </status>
    <current-order-no>00000301</current-order-no>
    <product-lineitems>
        <product-lineitem>
            <net-price>297.52</net-price>
            <tax>62.48</tax>
            <gross-price>360.00</gross-price>
            <base-price>120.00</base-price>
            <lineitem-text>Avene Antirougeurs Clean Verfrissende Melk 200ml</lineitem-text>
            <tax-basis>360.00</tax-basis>
            <position>1</position>
            <product-id>8711132</product-id>
            <product-name>Avene Antirougeurs Clean Verfrissende Melk 200ml</product-name>
            <quantity unit="st">3.0</quantity>
            <tax-rate>0.21</tax-rate>
            <shipment-id>00001501</shipment-id>
            <gift>false</gift>
        </product-lineitem>
    </product-lineitems>
    <shipping-lineitems>
        <shipping-lineitem>
            <net-price>4.05</net-price>
            <tax>0.85</tax>
            <gross-price>4.90</gross-price>
            <base-price>4.90</base-price>
            <lineitem-text>Shipping</lineitem-text>
            <tax-basis>4.90</tax-basis>
            <item-id>STANDARD_SHIPPING</item-id>
            <shipment-id>00001501</shipment-id>
            <tax-rate>0.21</tax-rate>
        </shipping-lineitem>
    </shipping-lineitems>
    <shipments>
        <shipment shipment-id="00001501">
            <status>
                <shipping-status>NOT_SHIPPED</shipping-status>
            </status>
            <shipping-method>homeDelivery</shipping-method>
            <shipping-address>
                <first-name>X</first-name>
                <last-name>X</last-name>
                <address1>X</address1>
                <address2>X</address2>
                <city>X</city>
                <postal-code>X</postal-code>
                <state-code>undefined</state-code>
                <country-code>X</country-code>
                <phone>X</phone>
            </shipping-address>
            <gift>false</gift>
            <totals>
                <merchandize-total>
                    <net-price>297.52</net-price>
                    <tax>62.48</tax>
                    <gross-price>360.00</gross-price>
                </merchandize-total>
                <adjusted-merchandize-total>
                    <net-price>297.52</net-price>
                    <tax>62.48</tax>
                    <gross-price>360.00</gross-price>
                </adjusted-merchandize-total>
                <shipping-total>
                    <net-price>4.05</net-price>
                    <tax>0.85</tax>
                    <gross-price>4.90</gross-price>
                </shipping-total>
                <adjusted-shipping-total>
                    <net-price>4.05</net-price>
                    <tax>0.85</tax>
                    <gross-price>4.90</gross-price>
                </adjusted-shipping-total>
                <shipment-total>
                    <net-price>301.57</net-price>
                    <tax>63.33</tax>
                    <gross-price>364.90</gross-price>
                </shipment-total>
            </totals>
        </shipment>
    </shipments>
    <totals>
        <merchandize-total>
            <net-price>297.52</net-price>
            <tax>62.48</tax>
            <gross-price>360.00</gross-price>
        </merchandize-total>
        <adjusted-merchandize-total>
            <net-price>297.52</net-price>
            <tax>62.48</tax>
            <gross-price>360.00</gross-price>
        </adjusted-merchandize-total>
        <shipping-total>
            <net-price>4.05</net-price>
            <tax>0.85</tax>
            <gross-price>4.90</gross-price>
        </shipping-total>
        <adjusted-shipping-total>
            <net-price>4.05</net-price>
            <tax>0.85</tax>
            <gross-price>4.90</gross-price>
        </adjusted-shipping-total>
        <order-total>
            <net-price>301.57</net-price>
            <tax>63.33</tax>
            <gross-price>364.90</gross-price>
        </order-total>
    </totals>
    <payments>
        <payment>
            <credit-card>
                <card-type>VISA</card-type>
                <card-number>XXXX-XXXX-XXXX-X</card-number>
                <card-holder>X X</card-holder>
                <card-token>X</card-token>
                <expiration-month>X</expiration-month>
                <expiration-year>X</expiration-year>
            </credit-card>
            <amount>364.90</amount>
            <processor-id>BASIC_CREDIT</processor-id>
            <transaction-id>00000301</transaction-id>
        </payment>
    </payments>
</order>

I even tried printing the XML attribute but in the email this code just returns nothing. The result is blank.

As you can see in the picture, the white space above the grey box is the empty result. And on the left you can see that the XML attribute is not empty.

enter image description here

Any help would be greatly appreciated!

  • maybe this can help`? ampscript.guide/buildrowsetfromxml I believe you will find a good example there. I would not set a rowset a firstname, i rather would get the field of that row. Maybe that is the first step. Although i am quite irritated that you do not get any result. – Johannes Schapdick Jun 24 '19 at 12:43
  • Yeah, that would be better indeed. But since the XML attribute comes up empty I don't know if that is the issue. – user3485470 Jun 24 '19 at 13:09
1

Set the XML into the variable.

%%[
set @xmltest = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order order-no="00000301">
    <order-date>2019-06-24T09:35:22.076Z</order-date>
    <created-by>storefront</created-by>
    <original-order-no>00000301</original-order-no>
    <currency>EUR</currency>
    <customer-locale>nl_BE</customer-locale>
    <taxation>gross</taxation>
    <invoice-no>00001501</invoice-no>
    <customer>
        <customer-no>00003001</customer-no>
        <customer-name>X</customer-name>
        <customer-email>X</customer-email>
        <billing-address>
            <first-name>X</first-name>
            <last-name>X</last-name>
            <address1>X</address1>
            <address2>X</address2>
            <city>X</city>
            <postal-code>X</postal-code>
            <state-code>undefined</state-code>
            <country-code>X</country-code>
            <phone>X</phone>
        </billing-address>
    </customer>
    <status>
        <order-status>NEW</order-status>
        <shipping-status>NOT_SHIPPED</shipping-status>
        <confirmation-status>CONFIRMED</confirmation-status>
        <payment-status>NOT_PAID</payment-status>
    </status>
    <current-order-no>00000301</current-order-no>
    <product-lineitems>
        <product-lineitem>
            <net-price>297.52</net-price>
            <tax>62.48</tax>
            <gross-price>360.00</gross-price>
            <base-price>120.00</base-price>
            <lineitem-text>Avene Antirougeurs Clean Verfrissende Melk 200ml</lineitem-text>
            <tax-basis>360.00</tax-basis>
            <position>1</position>
            <product-id>8711132</product-id>
            <product-name>Avene Antirougeurs Clean Verfrissende Melk 200ml</product-name>
            <quantity unit="st">3.0</quantity>
            <tax-rate>0.21</tax-rate>
            <shipment-id>00001501</shipment-id>
            <gift>false</gift>
        </product-lineitem>
    </product-lineitems>
    <shipping-lineitems>
        <shipping-lineitem>
            <net-price>4.05</net-price>
            <tax>0.85</tax>
            <gross-price>4.90</gross-price>
            <base-price>4.90</base-price>
            <lineitem-text>Shipping</lineitem-text>
            <tax-basis>4.90</tax-basis>
            <item-id>STANDARD_SHIPPING</item-id>
            <shipment-id>00001501</shipment-id>
            <tax-rate>0.21</tax-rate>
        </shipping-lineitem>
    </shipping-lineitems>
    <shipments>
        <shipment shipment-id="00001501">
            <status>
                <shipping-status>NOT_SHIPPED</shipping-status>
            </status>
            <shipping-method>homeDelivery</shipping-method>
            <shipping-address>
                <first-name>X</first-name>
                <last-name>X</last-name>
                <address1>X</address1>
                <address2>X</address2>
                <city>X</city>
                <postal-code>X</postal-code>
                <state-code>undefined</state-code>
                <country-code>X</country-code>
                <phone>X</phone>
            </shipping-address>
            <gift>false</gift>
            <totals>
                <merchandize-total>
                    <net-price>297.52</net-price>
                    <tax>62.48</tax>
                    <gross-price>360.00</gross-price>
                </merchandize-total>
                <adjusted-merchandize-total>
                    <net-price>297.52</net-price>
                    <tax>62.48</tax>
                    <gross-price>360.00</gross-price>
                </adjusted-merchandize-total>
                <shipping-total>
                    <net-price>4.05</net-price>
                    <tax>0.85</tax>
                    <gross-price>4.90</gross-price>
                </shipping-total>
                <adjusted-shipping-total>
                    <net-price>4.05</net-price>
                    <tax>0.85</tax>
                    <gross-price>4.90</gross-price>
                </adjusted-shipping-total>
                <shipment-total>
                    <net-price>301.57</net-price>
                    <tax>63.33</tax>
                    <gross-price>364.90</gross-price>
                </shipment-total>
            </totals>
        </shipment>
    </shipments>
    <totals>
        <merchandize-total>
            <net-price>297.52</net-price>
            <tax>62.48</tax>
            <gross-price>360.00</gross-price>
        </merchandize-total>
        <adjusted-merchandize-total>
            <net-price>297.52</net-price>
            <tax>62.48</tax>
            <gross-price>360.00</gross-price>
        </adjusted-merchandize-total>
        <shipping-total>
            <net-price>4.05</net-price>
            <tax>0.85</tax>
            <gross-price>4.90</gross-price>
        </shipping-total>
        <adjusted-shipping-total>
            <net-price>4.05</net-price>
            <tax>0.85</tax>
            <gross-price>4.90</gross-price>
        </adjusted-shipping-total>
        <order-total>
            <net-price>301.57</net-price>
            <tax>63.33</tax>
            <gross-price>364.90</gross-price>
        </order-total>
    </totals>
    <payments>
        <payment>
            <credit-card>
                <card-type>VISA</card-type>
                <card-number>XXXX-XXXX-XXXX-XXXX</card-number>
                <card-holder>X X</card-holder>
                <card-token>X</card-token>
                <expiration-month>2</expiration-month>
                <expiration-year>X</expiration-year>
            </credit-card>
            <amount>364.90</amount>
            <processor-id>BASIC_CREDIT</processor-id>
            <transaction-id>00000301</transaction-id>
        </payment>
    </payments>
</order>'
]%%

Seperated just for readability:

%%[
if indexOf(@xmltest,"<first-name>") > 0 then
    Output(v("Firstname Tag has been found <br>"))
     set @nodepath = '/order/customer/billing-address/first-name'
      set @firstname = Field(Row(BuildRowsetFromXML(@xmltest,@nodepath,0),1),'Value')
    Output(Concat("Firstname is :", @firstname))


else

    output(concat("<br>no firstname found"))

endif
]%%

You just needed to request the row and the field in order to get the firstname.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.