0

We are trying to bring into our emails dynamic content from our websites; I am working on a way to achieve this. I imported a sample of the XMLs that we would generate of the website into a Data Extension and I am trying to reference these via amp script. I do not get an error message I just receive a blank screen.

I saved the xmls in a non sendable data extension. Code I wrote is below:

%%[

var @SubscriberKey 
SET @rows = LookupOrderedRows('EE_BookingExtensions_Cris',0,'[Tour Number] desc','SubscriberKey',SubscriberKey) 
SET @rowcount = RowCount(@rows) 

if @rowcount > 0 then 
    for @i = 1 to @rowcount do 
        set @row = row(@rows,@i) 
        set @tour = field(@row,"Tour Number")
    ]%% 
    %%[next @i]%% 

    Tour Code from Sendable DE:%%=v(@tour)=%%<br>

%%[endif]%%

<br>

%%[

SET @xml = Lookuprows('XML_CRISSS','TourCode',@tour)

for @j = 1 to rowcount(@xml) do
    SET @xmlrows = row(@xml,@j)
    SET @xmlls = field(@xmlrows,"CODE__HTML")
    SET @brochure = BuildRowsetFromXML(@xmlls,'/TourInfo/SellingCompanies/SellingCompany/Brochure/Name',1)
    set @TourName = BuildRowsetFromXML(@xmlls,'/TourInfo/TourName',1)
]%%

%%[ next @j ]%%
<br>Your brochure is: %%=v(@brochure)=%%
<br>Your Tour Name is: %%=v(@TourName)=%%

Any guidance is appreciated.

Giuliettaenter image description here

1

Perhaps it's set somewhere else, but I don't see where you've assigned a value to @subscriberKey. It's also not referenced in your initial lookup properly -- the variable is missing the @ prefix.

Don't you want to nest your loops?

Can there be multiple XML_CRISSS records for a single Tour and multiple SellingCompanies per Tour?

Assuming that's the case, I've updated your code to match the format of my go-to XML parsing method.

It's better to check to make sure your XML nodes exist before trying to pull values out of them.

%%[
var @SubscriberKey 

set @subscriberkey = AttributeValue("_subscriberkey")

SET @rows = LookupOrderedRows('EE_BookingExtensions_Cris',0,'[Tour Number] desc','SubscriberKey', @SubscriberKey) 
SET @rowcount = RowCount(@rows) 

if @rowcount > 0 then 

    for @i = 1 to @rowcount do 

        set @row = row(@rows, @i) 
        set @tour = field(@row,"Tour Number")

        output(concat("<br>Tour Code from Sendable DE: ", @tour))

        SET @xml = Lookuprows('XML_CRISSS','TourCode', @tour)

        if rowcount(@xml) > 0 then 

            for @j = 1 to rowcount(@xml) do

                SET @xmlrows = row(@xml, @j)
                SET @xmlls = field(@xmlrows, "CODE__HTML")

                if indexOf(@xml,"<TourInfo>") > 0 then

                    set @nodes = BuildRowsetFromXML(@xml,"/TourInfo/SellingCompanies/SellingCompany",0)
                    set @rowCount = rowcount(@nodes)

                    for @k = 1 to @rowCount do

                        var @brochure
                        var @TourName

                        set @nodepath = concat("/TourInfo/SellingCompanies/SellingCompany[",@k,"]/")

                        if rowcount(BuildRowsetFromXML(@xml,concat(@nodepath,"Brochure"))) > 0 then
                            set @brochure = Field(Row(BuildRowsetFromXML(@xml,concat(@nodepath,"Brochure"),0),1),'Value')
                        endif

                        if rowcount(BuildRowsetFromXML(@xml,concat(@nodepath,"Name"))) > 0 then
                           set @TourName = Field(Row(BuildRowsetFromXML(@xml,concat(@nodepath,"Name"),0),1),'Value')
                        endif

                        output(concat("<br>Your brochure is: ", @brochure))
                        output(concat("<br>Your Tour Name is: ", @TourName))

                    next @k

                else 
                    output(concat("<br>no TourInfo found"))
                endif

            next @j 

        else
            output(concat("<br>no XML found"))
        endif

    next @i
else 
   output(concat("<br>no rows found"))
endif

]%%

IMPORTANT NOTE: XML path values in BuildRowSetFromXML() are case-sensitive

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.