3

When I try to use the below code, I'm not able to see a preview email; it just says there's an error in the email.

%%[

Var @xml, @titles, @title, @links, @link, @descs, @desc, @dates, @date, @cnt 

Set @xml = ContentArea("3618") 

Set @titles =
BuildRowsetFromXML(@xml,"//item/title",1) 
Set @links =
BuildRowsetFromXML(@xml,"//item/link",1) 
Set @descs =
BuildRowsetFromXML(@xml,"//item/description",1) 
Set @dates =
BuildRowsetFromXML(@xml,"//item/pubDate",1)


SET @rows = RowCount(@titles)
Set @date = Field(Row(@dates,@cnt), "Value")

IF @rows >= 1 THEN

    for @cnt = 1 to @rows do

        IF DateDiff(NOW(),@date, "D") <= 14 THEN


    for @cnt = 1 to @rows do 
        Set @title = Field(Row(@titles,@cnt), "Value") 
        Set @link = Field(Row(@links,@cnt), "Value") 
Set @desc = Field(Row(@descs,@cnt), "Value") ]%%


<h1><a title="%%=v(@title)=%%" alias="%%=v(@title)=%%"
href="%%=v(@link)=%%">%%=v(@title)=%%</a></h1>
<p>%%=v(@desc)=%% <br />%%=v(@date)=%%</p> </div>


%%[ 
        ENDIF
    NEXT @cnt 
ENDIF
]%%

Content Area 3618 is where I'm pulling in my RSS:


%%httpget; 0 "RSS FEED I'm USING"%%

RSS Structure Example

1
  • What happens when you paste the raw RSS XML (without the CR & LF) as a value for your @xml variable? Feb 22, 2016 at 18:31

1 Answer 1

0

Looks like you've got an extra FOR loop. Maybe something like this is what you intended:

%%[

Var @xml, @titles, @title, @links, @link, @descs, @desc, @dates, @date, @cnt 

Set @xml = ContentArea("3618") 

Set @titles = BuildRowsetFromXML(@xml,"//item/title",1) 
Set @links = BuildRowsetFromXML(@xml,"//item/link",1) 
Set @descs = BuildRowsetFromXML(@xml,"//item/description",1) 
Set @dates = BuildRowsetFromXML(@xml,"//item/pubDate",1)

SET @rows = RowCount(@titles)

IF @rows >= 1 THEN

    for @cnt = 1 to @rows do

        Set @date = Field(Row(@dates,@cnt), "Value")

        IF DateDiff(NOW(),@date, "D") <= 14 THEN

            Set @title = Field(Row(@titles,@cnt), "Value") 
            Set @link = Field(Row(@links,@cnt), "Value") 
            Set @desc = Field(Row(@descs,@cnt), "Value") 

            ]%%

            <h1><a title="%%=v(@title)=%%" alias="%%=v(@title)=%%" href="%%=v(@link)=%%">%%=v(@title)=%%</a></h1>
            <p>
                %%=v(@desc)=%% 
                <br />%%=v(@date)=%%
            </p>

            %%[ 
        ENDIF

    NEXT @cnt

ENDIF
]%%
4
  • Thanks Adam! I updated the code to remove the extra "for" loop, but I'm still getting: Invalid value specified for function parameter. Function Name: Row Parameter Name: Index Parameter Ordinal: 2 Parameter Type: Numeric Feb 22, 2016 at 19:14
  • Updated my example. The setting of @date was in the wrong place. Needed to be inside the loop, since it referenced @cnt. Feb 22, 2016 at 19:20
  • Hmm...looks like all my RSS items are showing and not just the ones from the past 14 days; do I need to do anything to reformat my dates in the RSS feed? Feb 22, 2016 at 19:38
  • I just swapped the DateDiff so @date was listed first; that did the trick. Feb 22, 2016 at 19:56

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.