0

I am using several AMPscript blocks to import xml order data from Commerce Cloud into a Marketing Cloud Data Extension, ex:


 set @P18_orderno = concat("//order/product-lineitems/product-lineitem[",@j,"]/position")
     set @rs18_orderno = BuildRowSetFromXML(@xml, @P18_orderno, 1)
     if rowcount(@rs18_orderno) !=  0 then
      set @position= Field(row(@rs18_orderno, 1), 1)
     endif

We have a custom xml field we have created that we need to store in the data extension, ex:

<custom-attribute attribute-id=""bazaarvoiceUserToken"">ab6616d770fb6bf80687d9da854c4ec87b2d4638a0d0a586d25177558f1a1459646174653d323032332d30372d3034267573657269643d303030303230303326656d61696c616464726573733d636a616e7a656e407765737465726e676c6f76652e6d622e6361266d61786167653d33302676657269666965647075726368617365723d5472756526686f737465643d5645524946494544</custom-attribute>

After trying several combinations of AMPscript code blocks and variables such as:

SET @P24_orderno = Concat("//order/product-lineitems/product-lineitem[", @j, "]/[custom-attribute attribute-id=””bazaarvoiceUserToken””]")
    SET @rs24_orderno = BuildRowsetFromXML(@xml, @P24_orderno, 1)
    IF RowCount(@rs24_orderno) != 0 THEN
        SET @[custom-attribute attribute-id=””bazaarvoiceUserToken””]= Field(@row24_orderno, 1)
    ENDIF

I continue to receive the following when trying to run the script

ERROR: A runtime error occurred while the SSJS Activity executed the SSJS script. Please review the SSJS activity to ensure that errors are handled properly.

Has anyone ever converted a custom Commerce Cloud xml attribute using AMPscript so it can be stored in a Marketing Cloud data extension? Any advice would be greatly appreciated.

1 Answer 1

1

You can reference those attributes using an XPATH pattern like this:

%%[

if rowcount(BuildRowsetFromXML(@OrderAsXML, '//order/custom-attributes/custom-attribute[@attribute-id="entryType"]')) > 0 then

    set @entryType = Field(Row(BuildRowsetFromXML(@OrderAsXML, '//order/custom-attributes/custom-attribute[@attribute-id="entryType"]',0),1), 'Value')

endif

]]%

There are several sites for XML XPATH testing that I've found helpful:

NOTE: The BuildRowsetFromXML() function only supports the XPATH 1.0 standard.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .