0

I am trying to display firstname and lastname of patient under one doctor if field Date_FX_Plan_Approved__c is null. First I'm trying to pass subscriber key (Id) to @Idd which is in Acc DE, then do lookup on Account_Salesforce DE to the fetch firstname, lastname. There can be multiple patients under one doctor, so my objective is to retrieve patients full name where there Date_FX_Plan_Approved__c is null/

The error I am receiving is

The subscriber preview failed to generate. Review the details, correct all issues, and try again. An IF statement is not closed with the required ENDIF statement. ClientID: 514001327 JobID: 0 EmailID: 0 Index: 2984 Statement: if @rowCount > 0 then for @i = 1 to @rowCount do var @firstName, @emailAddress, @rank @Date_FX_Plan_Approved__cc set @row = row(@rows, @i) /* get row based on counter */ set @rank = field(@row,"Id") set @firstName = field(@row,"FirstName") set @emailAddress = field(@row,"LastName") set @Date_FX"

The code:

%%[ 

var @rows, @row, @rowCount, @numRowsToReturn, @region, @i , @Id, @Date_FX_Plan_Approved__c , @Idd , @firstName, @lastName, @rank , @Date_FX_Plan_Approved__cc

set @Id = AttributeValue("Doctor__c") 
set @Idd = AttributeValue("Id") 
set @numRowsToReturn = 0 /* 0 means all, max 2000 */ 
set @rows = LookupOrderedRows("Acc", @numRowsToReturn, "Id desc, Name asc", "Id", @Idd) 
set @Date_FX_Plan_Approved__c = Lookup("Account_Salesforce", "Date_FX_Plan_Approved__c", "Id" , @Idd) 
set @rowCount = rowcount(@rows) 

for @i = 1 to @rowCount do 

  set @row = row(@rows, @i) /* get row based on counter */ 
  set @rank = field(@row,"Id") 
  set @firstName = field(@row,"FirstName") 
  set @lastName = field(@row,"LastName")

]%% 

%%[ next @i ]%% 

%%[ else ]%% 

  No rows found 

%%[ endif ]%%

IF EMPTY(@Date_FX_Plan_Approved__cc) THEN
  SET @ln = @lastName
  SET @fn = @firstName
ELSE
  SET @ln = @lastName 
  SET @fn = @firstname
ENDIF

]%%
%%=v(@ln)=%%, %%=v(@fn)=%%
3
  • Have you tried debugging using try catch block on a cloud page? Also, is there any other block of ampscript above this? – Swati Mishra Oct 22 '20 at 8:00
  • Hi Swati, I am doing workaround for this since it is still giving error, I am using sql to store all patients records in DE where there Date_FX_Plan_Approved__c is null and using same ampscript on this DE, I have nt used catch block as you mentioned, its not in cloudpage but its in email, i have updated my ampscript looks like above one is not correctlyt pasted.only if i remove IF EMPTY it works, nto sure whats wrong in that IF EMPTY – sfmc poc Oct 22 '20 at 10:04
  • You have an extra endif on line16 – Swati Mishra Oct 22 '20 at 10:37
0

You've got some issues with your loop and conditionals as @Swati suggested. I suggest taking the time to indent your code. There's a missing if-then checking your row count. Not sure your intent with the if empty(@Date_FX_Plan_Approved_cc) then conditional. You're not setting @Date_FX_Plan_Approved_cc anywhere that I can see. Additionally, both the then and else are assigning the same values.

Perhaps you can update your question to provide some sample data from your sending Data Extension (including Doctor_cc and id), Acc and Account_Salesforce, and the desired output.

I've added some debugging output to help validate your conditionals:

%%[ 

set @debug = 1 /* set to zero to disable debugging output */

set @Id = AttributeValue("Doctor__c") 
set @Idd = AttributeValue("Id") 
set @numRowsToReturn = 0 /* 0 means all, max 2000 */ 
set @rows = LookupOrderedRows("Acc", @numRowsToReturn, "Id desc, Name asc", "Id", @Idd) 
set @Date_FX_Plan_Approved__c = Lookup("Account_Salesforce", "Date_FX_Plan_Approved__c", "Id" , @Idd) 
set @rowCount = rowcount(@rows) 

if @debug = 1
  output(concat("<br>id: ", @id))
  output(concat("<br>Idd: ", @Idd))
  output(concat("<br>Date_FX_Plan_Approved__c: ", @Date_FX_Plan_Approved__c))
  output(concat("<br>rowCount: ", @rowCount))
endif

if @rowCount > 0 then 

  for @i = 1 to @rowCount do 

    set @row = row(@rows, @i) /* get row based on counter */ 
    set @firstName = field(@row,"FirstName") 
    set @lastName = field(@row,"LastName")

    IF EMPTY(@Date_FX_Plan_Approved__cc) THEN
      SET @ln = @lastName
      SET @fn = @firstName
    ELSE
      SET @ln = @lastName 
      SET @fn = @firstname
    ENDIF  

    output(concat("<br>ln: ", @ln))
    output(concat("<br>fn: ", @fn))
 
  next @i

else 

  output(concat("<br>No rows found"))

endif 

]%%

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.