views:

57

answers:

3

Right, I'm working on a site with a couple different RSS feeds. My issue is one of my feeds works just fine, but the second one (based on nearly identical code) fails and I can't figure out why.

Here's the code that works:

<!--- Get the feed data as a query from the orders table. ---> 
<cfquery name="getNews" datasource="#DSN#">  
    SELECT * FROM NEWS2
    WHERE STATUS = 1 
    ORDER BY rdate DESC
</cfquery>  


<cfset myStruct = StructNew() />
<cfset mystruct.link = "http://noobzilla.net" />
<cfset myStruct.title = "Noobzilla News" />
<cfset mystruct.description = "Programming Related Site Reviews" />
<cfset mystruct.pubDate = Now() />
<cfset mystruct.version = "rss_2.0" />
<cfset myStruct.item = ArrayNew(1) />

<cfloop query="getNews">
    <cfset myStruct.item[currentRow] = StructNew() />
    <cfset myStruct.item[currentRow].guid = structNew() />
    <cfset myStruct.item[currentRow].guid.isPermaLink="YES" />
    <cfset myStruct.item[currentRow].guid.value = 'http://noobzilla.net/news-detail.cfm?id=#id#' />    
    <cfset myStruct.item[currentRow].pubDate = "#DateFormat(getNews.rdate, "mm/dd/yyyy")#" />
    <!---<cfset myStruct.item[currentRow].title = xmlFormat(title) />--->
    <cfset myStruct.item[currentRow].title = #title# />
    <cfset myStruct.item[currentRow].description = StructNew() />
    <!---<cfset myStruct.item[currentRow].description.value = xmlFormat(#info#) />--->
    <cfset myStruct.item[currentRow].description.value = '#Left(info, 250)#...' />
    <cfset myStruct.item[currentRow].link = 'http://noobzilla.net/news-detail.cfm?id=#id#' />
</cfloop>

<!--- Generate the feed and save it to a variable. --->
<cffeed action="create" name="#myStruct#" overwrite="true" xmlVar="myXML" />

The above code works great. Now here's the code from my second file (as you can see its virtually identical, just using a different table):

<!--- Get the feed data as a query from the orders table. ---> 
<cfquery name="getNews" datasource="#DSN#">  
    SELECT * FROM NEWS
    WHERE STATUS = 1 
    ORDER BY rdate DESC
</cfquery> 

<cfset myStruct = StructNew() />
<cfset mystruct.link = "http://noobzilla.net" />
    <cfset myStruct.title = "IDE Reviews" />
<cfset mystruct.description = "IDE and SDK Reviews" />
<cfset mystruct.pubDate = Now() />
<cfset mystruct.version = "rss_2.0" />
<cfset myStruct.item = ArrayNew(1) />

<cfloop query="getNews">
    <cfset myStruct.item[currentRow] = StructNew() />
    <cfset myStruct.item[currentRow].guid = structNew() />
    <cfset myStruct.item[currentRow].guid.isPermaLink="YES" />
    <cfset myStruct.item[currentRow].guid.value = 'http://noobzilla.net/news-detail2.cfm?id=#id#' />    
    <cfset myStruct.item[currentRow].pubDate = "#DateFormat(getNews.rdate, "mm/dd/yyyy")#" />
    <cfset myStruct.item[currentRow].title = #title# />
    <cfset myStruct.item[currentRow].description = StructNew() />
    <cfset myStruct.item[currentRow].description.value = '#Left(info, 250)#...' />
    <cfset myStruct.item[currentRow].link = 'http://noobzilla.net/news-detail2.cfm?id=#id#' />
</cfloop>

<!--- Generate the feed and save it to a variable. --->
<cffeed action="create" name="#myStruct#" overwrite="true" xmlVar="myXML" />

This second set of code generates the following error:

There was an error parsing a date specified in pubDate. Unable to convert pubDate to a date.

+2  A: 

I would check the getNews.rdate values and make sure its any standard date or date/time format accepted by ColdFusion.

Pragnesh Vaghela
Thanks for responding Pragnesh! That's exactly what the issue was.
noobzilla
+1  A: 

This is a code sample of solution proposed by Pragnesh:

<cfif isDate(getNews.rdate)>
    <cfset myStruct.item[currentRow].pubDate = DateFormat(getNews.rdate, "mm/dd/yyyy") />
<cfelse>
    <cfset myStruct.item[currentRow].pubDate = DateFormat(Now(), "mm/dd/yyyy") />
</cfig>
Sergii
Thanks for the code snippet Sergii!
noobzilla
A: 

Ben, Sergii and Pragnesh - Thanks for all your responses. I can be a little dense at times. I got caught up on the fact that the error must be stemming from this first line:

I double checked my data per your suggestions and there it was - a record with no data for rdate.

Cheers!

noobzilla