0

I'm trying to build some logic using AMPscript to only pull RSS entries if the "lastBuildDate" (or last day that a post was published) is within the past week. I'm having a hard time pulling the date from the feed.

I can get all the info I want from individual items, but I can't pull any of the values specific to the feed itself (title feed, description, language, etc.).

Here's my code:

<h1 style="font: bold normal 1.0em Arial, Helvetica, sans-serif;">LEVEL ONE</h1>
%%[Set @xml = ContentAreaByName("my contents\RSSParse-level-one")
Set @titles = BuildRowsetFromXML(@xml,"//item/title",1)
Set @descs = BuildRowsetFromXML(@xml,"//item/description",1)
Set @pubdas = BuildRowsetFromXML(@xml,"//item/pubDate",1)
Set @links = BuildRowsetFromXML(@xml,"//item/link",1)
Set @builddates = BuildRowsetFromXML(@xml,"//lastBuildDate",1)
Set @builddate = Field(Row(@builddates,1), "Value")

SET @rows = RowCount(@titles)


IF @rows >= 1 THEN
for @cnt = 1 to @rows do
Set @pubda = Field(Row(@pubdas,@cnt), "Value")
IF DateDiff(NOW(),@pubda, "D") <= 7 THEN
Set @title = Field(Row(@titles,@cnt),"Value")
Set @desc = Field(Row(@descs,@cnt), "Value")
Set @link = Field(Row(@links,@cnt), "Value") ]%%

<div style="border-bottom: 1px  solid #CBCAD2; padding-bottom:5px; padding-top:3px;">
<a style="text-decoration:none; color: #000000; font-weight: bold; font-size: 16px; font-family: Arial, Helvetica, sans-serif;" href="%%=RedirectTo(@link)=%%" alias="%%=v(@title)="%%" title="%%=v(@title)=%%">%%=v(@title)=%%</a><span style=" font-size:11px; text-decoration:none; font-weight: normal;">     |      %%=Format(@pubda, "MMMM d, yyyy")=%%</span><br/>
%%=v(@desc)=%%<br/>%%=v(@xml)=%%%%=v(@builddate)=%%
</div>

%%[ 
ENDIF
NEXT @cnt 
ELSE ]%%
<h1 style="font: bold normal 1.0em Arial, Helvetica, sans-serif;">Nothing to Display</h1>
%%[
ENDIF
]%%

<table cellpadding="2" cellspacing="0" width="600" ID="Table5" Border=0><tr><td><font face="verdana" size="1" color="#444444">This email was sent by: <b>%%Member_Busname%%</b><br>%%Member_Addr%% %%Member_City%%, %%Member_State%%, %%Member_PostalCode%%, %%Member_Country%%<br><br></font></td></tr></table>
<a href="%%profile_center_url%%" alias="Update Profile">Update Profile</a>
<custom name="opencounter" type="tracking">

Specifically, I need help with this part:

Set @builddates = BuildRowsetFromXML(@xml,"//lastBuildDate",1)
Set @builddate = Field(Row(@builddates,1), "Value")
3
  • Would you mind posting a link to the RSS feed you're trying to parse? Apr 6, 2015 at 21:27
  • @AdamSpriggs link
    – Zack
    Apr 8, 2015 at 17:34
  • What I posted, should still work if you update the RSS feed in the httpget() line. Apr 8, 2015 at 18:56

1 Answer 1

0

I don't see any issue with your @builddates code.

What you're doing is retrieving all of the nodes by name when you specify them like //item/title. Your loop is iterating through all of the pubDate nodes and you're assuming that there's a description, link, etc., for each pubDate. It may be true but not necessarily.

If you only want posts in the last 7 days, you need to flip your dateDiff() dates.

Displaying your @xml value won't display, since the browser will try to render it -- unless you replace the > and < with &gt; and &lt;

I like to output the raw values before I add the HTML. Here's an updated version with the output.

%%[
var @xml
set @xml = httpget("http://www.degdigital.com/feed")

Set @titles = BuildRowsetFromXML(@xml,"//item/title",1)
Set @descs = BuildRowsetFromXML(@xml,"//item/description",1)
Set @pubdas = BuildRowsetFromXML(@xml,"//item/pubDate",1)
Set @links = BuildRowsetFromXML(@xml,"//item/link",1)
Set @lastBuildDate = BuildRowsetFromXML(@xml,"//lastBuildDate",1)
Set @builddate = Field(Row(@lastBuildDate,1), "Value")
outputline(concat("<br>@builddate: ",@buildDate))
outputline(concat("<br>@builddate (formatted): ",format(@builddate,"MMMM d, yyyy")))
SET @rowCount = RowCount(@titles)

if @rowCount >= 1 THEN

    for @i = 1 to @rowCount do

        Set @pubda = Field(Row(@pubdas,@i), "Value")

        outputline(concat("<br>@pubda: ",@pubda))
        outputline(concat("<br>now(): ",NOW()))
        outputline(concat("<br>DateDiff(@pubda,NOW(), 'D'): ",DateDiff(@pubda,NOW(), "D")))

        if DateDiff(@pubda,NOW(), "D") <= 7 THEN
            Set @title = Field(Row(@titles,@i),"Value")
            Set @desc = Field(Row(@descs,@i), "Value")
            Set @link = Field(Row(@links,@i), "Value") 
]%%
            <br>@link: %%=v(@link)=%%
            <br>@title: %%=v(@title)=%%
            <br>@pubda: %%=v(@pubda)=%%
            <br>@desc: %%=v(@desc)=%%
%%[ 
        endif
    next @i 
else 
]%%

<br>no rows

%%[ endif ]%%

Output:

@builddate: Fri, 03 Apr 2015 21:46:17 +0000 
@builddate (formatted): April 3, 2015 
@pubda: Thu, 02 Apr 2015 16:15:43 +0000 
now(): 4/6/2015 3:52:10 PM 
DateDiff(@pubda,NOW(), 'D'): 4 
@link: http://www.degdigital.com/blog/brand-april-fools-day-email-campaigns 
@title: Psych! Best Brand April Fools’ Day Email Campaigns 
@pubda: Thu, 02 Apr 2015 16:15:43 +0000 
@desc:
April Fools’ Day: A whole day dedicated to shenanigans, tomfoolery, and laughs. Plenty of companies showed they could recognize the holiday in their email marketing. While some brands kept it simple with subject lines, sales, and promo codes geared toward the holiday, others went all out. While it could be construed as risky to send […]

The post Psych! Best Brand April Fools’ Day Email Campaigns appeared first on DEG.


@pubda: Mon, 30 Mar 2015 15:04:00 +0000 
now(): 4/6/2015 3:52:10 PM 
DateDiff(@pubda,NOW(), 'D'): 7 
@link: http://www.degdigital.com/blog/how-google-emphasis-on-mobile-affects-websites 
@title: How Google’s Emphasis on Mobile Will Affect Your Website 
@pubda: Mon, 30 Mar 2015 15:04:00 +0000 
@desc:
The “mobile first” movement is getting a major boost. Google announced on its webmaster blog that, on April 21, it will be expanding its use of mobile-friendliness as a ranking signal. Starting April 21, we will be expanding our use of mobile-friendliness as a ranking signal. This change will affect mobile searches in all languages worldwide […]

The post How Google’s Emphasis on Mobile Will Affect Your Website appeared first on DEG.


@pubda: Thu, 12 Mar 2015 15:43:28 +0000 
now(): 4/6/2015 3:52:10 PM 
DateDiff(@pubda,NOW(), 'D'): 25 
@pubda: Tue, 10 Mar 2015 15:00:04 +0000 
now(): 4/6/2015 3:52:10 PM 
DateDiff(@pubda,NOW(), 'D'): 27 
@pubda: Thu, 05 Mar 2015 19:21:13 +0000 
now(): 4/6/2015 3:52:10 PM 
DateDiff(@pubda,NOW(), 'D'): 32 
@pubda: Mon, 02 Mar 2015 15:33:11 +0000 
now(): 4/6/2015 3:52:10 PM 
DateDiff(@pubda,NOW(), 'D'): 35 
@pubda: Thu, 26 Feb 2015 19:48:35 +0000 
now(): 4/6/2015 3:52:10 PM 
DateDiff(@pubda,NOW(), 'D'): 39 
@pubda: Tue, 24 Feb 2015 16:15:03 +0000 
now(): 4/6/2015 3:52:10 PM 
DateDiff(@pubda,NOW(), 'D'): 41 
@pubda: Thu, 19 Feb 2015 16:15:45 +0000 
now(): 4/6/2015 3:52:10 PM 
DateDiff(@pubda,NOW(), 'D'): 46 
@pubda: Tue, 17 Feb 2015 17:48:18 +0000 
now(): 4/6/2015 3:52:10 PM 
DateDiff(@pubda,NOW(), 'D'): 48
1
  • This is very helpful. I didn't know how to output the HTML, so that helped a lot. I'm going to try to use this logic to filter whether a user-initiated send goes out or not.
    – Zack
    Apr 9, 2015 at 20:47

You must log in to answer this question.

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