0

I'm using the following AMPscript to set variables and to allow fallback values if data isn't available for a Guardian.

%%[ 
SET @rows = LookupRows("Contact_Salesforce","Id", _subscriberkey) 
SET @row = row(@rows,1) 
SET @firstName = field(@row,"firstName") 
SET @He_She__c = field(@row,"He_She__c") 
SET @Guardian_First_Name__c = field(@row,"Guardian_First_Name__c") 
IF NOT EMPTY(@Guardian_First_Name__c) THEN ]
%% Dear %%=v(@Guardian_First_Name__c)=%%,
%%[ELSE]%% Hello,%%
[ENDIF]%%

It works in 99% of cases, but I've just noticed that it triggers an error in 1% of cases when testing some new data.

I get this error:

Invalid index (parameter 2) passed to Row function. Index must be less than or equal to the row count. Index Value: 1 Row Count: 0 Function: row(@rows,1)

Can anyone shed any light on this? To my simple brain, this seems like an error that should happen in all cases, not a select few.

  • 1
    This error means that the subscriber (who triggered this error) is not found in Contact_Salesforce data extension. Is it possible that those who got the error are Leads or did not origin from Salesforce at all? – zuzannamj Feb 28 at 20:50
  • Thank you, in that case this is nothing for me to worry about. – Thomas Hockey Feb 28 at 21:06
3

I'd recommend explicitly checking the rowcount as a defensive measure. You could also do a raiseError() in an ELSE to skip the send to the subscriber.

%%[ 

SET @rows = LookupRows("Contact_Salesforce","Id", _subscriberkey) 

set @firstName = ""
set @He_She__c = ""
set @Guardian_First_Name__c = ""

if rowcount(@rows) > 1 then 

    SET @row = row(@rows,1) 
    SET @firstName = field(@row,"firstName") 
    SET @He_She__c = field(@row,"He_She__c") 
    SET @Guardian_First_Name__c = field(@row,"Guardian_First_Name__c") 

endif

IF NOT EMPTY(@Guardian_First_Name__c) THEN 

]%% 

Dear %%=v(@Guardian_First_Name__c)=%%,

%%[ ELSE ]%% 

Hello,

%%[ ENDIF ]%%
| improve this answer | |

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.