Salesforce Asked on November 30, 2021
I have the below AMPScript that isn’t quite right. What i want it to do is output data form a data extension that was added to the Data Extension within the last 24 hrs. I want to add the code to an email which will be run by an automation to send to a 3rd party once a day to give them the latest leads. We are based in New Zealand so to do the "formsubmitdate >= Now()" check I using the default value (Current date) in the data extension so uses the Marketing Cloud US Data Stamp but it doesn’t seam to work. What am i missing?
If i edit the code i either get no rows found (Yet a recent test submission has been made) or it includes all submissions outside of the 24hrs
<tr>
<td style="width: 20%;"><b>Date Submitted</b></td>
<td style="width: 30%;"><b>First Name</b></td>
<td style="width: 30%;"><b>Last Name</b></td>
<td style="width: 20%;"><b>Email Address</b></td>
<td style="width: 20%;"><b>Contact Number</b></td>
<td style="width: 20%;"><b>Customer Comments/Product Interested in</b></td>
</tr>
%%[
var @rows, @row, @DateSubmitted, @FirstName, @LastName, @EmailAddress, @ContactPhoneNumber, @Product, @formsubmitdate, @i
set @rows = lookuprows("leadform", "SubmitMethod","online")
set @chkDate = DateAdd(now(),-24,"h")
FOR @i = 1 to RowCount(@rows) DO
set @DateSubmitted = field(Row(@rows,@i),'DateSubmitted')
set @FirstName = field(Row(@rows,@i),'FirstName')
set @LastName = field(Row(@rows,@i),'LastName')
set @EmailAddress = field(Row(@rows,@i),'EmailAddress')
set @ContactPhoneNumber = field(Row(@rows,@i),'Contact Phone Number')
set @Product = field(Row(@rows,@i),'Product')
set @formsubmitdate = field(Row(@rows,@i),'formsubmitdate')
IF @formsubmitdate >= @chkDate THEN
]%%
<tr>
<td style="width: 20%;">%%=v(@DateSubmitted)=%%</td>
<td style="width: 20%;">%%=v(@FirstName)=%%</td>
<td style="width: 20%;">%%=v(@LastName)=%%</td>
<td style="width: 20%;">%%=v(@EmailAddress)=%%</td>
<td style="width: 20%;">%%=v(@ContactPhoneNumber)=%%</td>
<td style="width: 20%;">%%=v(@Product)=%%</td>
</tr>
%%[
ELSE
RaiseError('No rows found')
]%%
%%[
ENDIF
NEXT @i
]%%
</table>
First, it seems the value you passed as third argument into DateAdd() is not valid. Instead of "h", try "H".
Second, I would suggest setting a variable with the value for Now(). Then pass it into DateAdd() as first parameter.
set @currentDate = Now()
set @chkDate = DateAdd(@currentDate,-24,"H")
Answered by Willem Ruys on November 30, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP