0

I have an rss-feed problem that I wonder if you could help me with.

How do I check - with ampscript in an email - if a node exists in an item or not? If one of the node exists that will be used to populate parts of the email ELSE the other node/nodes will be used.

Structure of RSS feed is like this

<items>
    <item>
        <title>Movietitle</title>
        <prodyear><1976</prodyear>
    </item>
    <item>
        <title>Seriestitle</title>
        <season>3</season>
        <episode>147</episode>
    </item>
</items>

So sometimes there is a production year (= movie) and sometimes there is season/eposide number (= series)

I need to populate an email based on this. I have a lot of other items and all works fine except for this.

Based on this code:

%%[

Set @bottom1_prodyears = BuildRowsetFromXML(@xml_bott,"//item/prodyear",1)
Set @bottom1_epis = BuildRowsetFromXML(@xml_bott,"//item/episodenumber",1)
Set @bottom1_seas = BuildRowsetFromXML(@xml_bott,"//item/season",1)

if (@bottom1_prodyears == "") OR (isNull(@bottom1_prodyears)) then

    Set @bottom1_epi = Field(Row(@bottom1_epis,1), "Value")
    Set @bottom1_sea = Field(Row(@bottom1_seas,1), "Value")

else then

    set @bottom1_prodyear = Field(Row(@bottom1_prodyears,1), "Value")

endif

]%%

But how ever I do this, I end up with it being a series. So question is: How do I check - with ampscript - if a node exists in an item or not?

Thanks a lot in advance for any hint. Best regards /Tove Walden

  • Hi Tove, welcome to SFSE! Please take a moment to visit the help center and read How to Ask. Please refrain from using the word urgent in your posts. – Adrian Larson Aug 16 '16 at 20:50
0

You'll want to use rowCount() to check to see if there are results:

%%[

Set @bottom1_prodyears = BuildRowsetFromXML(@xml_bott,"//item/prodyear",1)
Set @bottom1_epis = BuildRowsetFromXML(@xml_bott,"//item/episodenumber",1)
Set @bottom1_seas = BuildRowsetFromXML(@xml_bott,"//item/season",1)

if rowcount(@bottom1_prodyears) == 0 then

  if rowcount(@bottom1_epis) > 0 and rowcount(@bottom1_seas) > 0 then 

    Set @bottom1_epi = Field(Row(@bottom1_epis,1), "Value")
    Set @bottom1_sea = Field(Row(@bottom1_seas,1), "Value")

  else 

    Set @bottom1_epi = "not found"
    Set @bottom1_sea = "not found"

  endif 

else

    set @bottom1_prodyear = Field(Row(@bottom1_prodyears,1), "Value")

endif

]%%

Here's a snip of another method that's a little more fault-tolerant:

%%[

set @nodes = BuildRowsetFromXML(@xml,"/shipment/items/*",0)
set @rowCount = rowcount(@nodes)

for @i = 1 to @rowCount do

    if rowcount(BuildRowsetFromXML(@xml,concat("/shipment/items/item[",@i,"]/trackNbr"),0)) > 0 then
      set @trackNbr = Field(Row(BuildRowsetFromXML(@xml,concat("/shipment/items/item[",@i,"]/trackNbr"),0),1),'Value')
    endif

    /* repeat for other fields */

next @i

]%%
0

OK I know I shouldn't write a comment in an answer like this, but since I am new here I am left with no other choice (I cannot comment with less than 50 in reputation...) So here we go:

Thanks you so much for your good reply, however it seems to leave me with the same problem as before, or am I doing something really wrong?

As I do not know what nodes will hold the prodyear OR season/episode, it doesn't work with just counting the rows.

Say that out of 7 items, there are 2 (somewhere in the feed) holding "prodyear" and (maybe) 5 holding "episode" and "season". I need to list them all, one after the other. And IF item number 3 holds prodyear, I need to populate the corresponding table in the email with that information, ELSE I need to populate it with season/episode.

So I need to keep track of what items are what. Movie or series?

So I guess that I somehow will need to loop through all items and find if item 1 is movie or series, if item 2 is movie or series... and so on?

Any idea on how to know what item is what? Thanks :-) /Tove

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.