0

I'm getting the following error detail from my email: Invalid row (parameter 1) passed to Field function. Row is null or empty. Function: field(@customerReferralData, 'voucher_code')

Here's the specific code snippet that's triggering this error:

%%[

@var @referrerFirstName, @referrerLastName, @customerData, @customerReferralData, @voucherCode, @voucherCreditValue, @freebiesLeft, @freebieValidTill

IF @isCustomerEmail THEN
 SET @customerId = AttributeValue('referrer_customer_id')
 SET @customerBusinessUnit = AttributeValue('business_unit')
 SET @userId = Concat(@customerId, '_', @customerBusinessUnit)
 SET @customerReferralDataById = LookUpRows('referrer', 'customer_id', @customerId)

 IF Empty(@userId) THEN
   RaiseError('Oops!! Looks like the wrong Data Extension is being used', true)
 ENDIF

 /* get referer personal data from customer DExt   */
 SET @customerByUserId = LookupRows('customer', 'user_id', @userId)
 SET @customerRowCount = rowcount(@customerByUserId)

 IF @customerRowCount > 0 THEN
   SET @customerData = row(@customerByUserId, 1)
   SET @referrerFirstName = field(@customerData, 'first_name')
   SET @referrerLastName = field(@customerData, 'last_name')
 ENDIF

 SET @rowCount = RowCount(@customerReferralDataById)

 SET @loopOptOut = false
 for @i = 1 to @rowCount do
  SET @row = Row(@customerReferralDataById, @i)
  SET @rowBusinessUnit = field(@row, 'business_unit')
  IF @rowBusinessUnit == @customerBusinessUnit and @loopOptOut != true THEN
   SET @customerReferralData = @row
   SET @loopOptOut = true
  ENDIF
 next @i

 IF not isNull(@customerReferralData) THEN
  SET @gotcha = 'I got here'
  SET @voucherCode = field(@customerReferralData, 'voucher_code',0)
  SET @voucherCreditValue = field(@customerReferralData, 'voucher_credit_value',0)
  SET @freebiesLeft = field(@customerReferralData, 'freebies_left')
  SET @dateOfLastFreebieAdded = field(@customerReferralData, 'date_of_last_freebie_added',0)
  
  IF not Empty(@dateOfLastFreebieAdded) THEN
  SET @freebieValidTill = FormatDate(DateAdd(@dateOfLastFreebieAdded, 21, "D"), "dd-MM-yyyy")
  ENDIF
  
  SET @email = AttributeValue('email')
 SET @verificationCode = Lookup("ent.verification_code", "verification_code", "email", @email)
  
 ENDIF
 
 
]%%

I've identified that this syntax "IF not isNull(@customerReferralData)" doesn't check if the a row is empty or not as it only works for field values. So, is there a way to check if a row is empty or is there a better way to rewrite that section?

4
  • The solution is already in your code a bit earlier. To determine the existence of a row based on a condition, use lookuprows() to look for it, and rowcount() on the resulting rowset. if it's 0, there are no matching rows, else you're set. Jan 14 at 16:57
  • Thanks for taking the time to respond. I already used lookuprows earlier on to get the rows but here's my challenge particularly for "customerReferralData", we often have multiple records in the DE with the same customerID but they represent different customers in different countries (E.g a customer has ID: 1234 but business unit: US, another customer has same ID: 1234 but business unit: GB). Due to that I have to match on customerID and business unit so that I get the right values. I do this using a loop. After the loop, how can I check if the row is not null? Can I also use rowcount here? Jan 14 at 18:05
  • maybe I am not getting the question, but I think that setup makes no difference. you can do a lookuprows() specifying multiple conditions. Like, lookup all rows where Business Unit = whatever and ID = "the id retrieved before". it returns a rowset all the same, and then rowcount() can be used. ampscript.guide/lookuprows - check "4a" and "4b" Jan 14 at 18:33
  • Oh! Didn't know that. I'll look into it. Thanks for the pointer Jan 14 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.