[SalesForce] AMPscript Lookup fails to find record

Having trouble with lookup not returning what's expected.

The @LOTeamName is what I'm having trouble returning. No errors when I run it, it just doesn't return anything even though I know it's there.

%%[

/* Find LO Info */
/* Find OwnerID - Look in contacts first then leads */
Set @rsContacts = LookupRows("Contact_Salesforce","ID",_Subscriberkey)

If RowCount(@rsContacts) > 0 Then
 Set @OwnerID = Field(Row(@rsContacts,1),"OwnerID")
Else

 Set @rsLeads = LookupRows("Lead_Salesforce","ID",_Subscriberkey)

 If RowCount(@rsLeads) > 0 Then
  Set @OwnerID = Field(Row(@rsLeads,1),"OwnerID")
 EndIf

EndIf

)

/* Find user info */
If Not Empty(@OwnerID) Then

 Set @rsUsers = LookupRows("User_Salesforce","Id",@OwnerID)

 if RowCount(@rsUsers) > 0 then

  Set @LOFirstName = Field(Row(@rsUsers,1),"FirstName")
  Set @LOLastName = Field(Row(@rsUsers,1),"LastName")
  Set @LOTitle = Field(Row(@rsUsers,1),"Title")
  Set @LO_NMLS_Number = Field(Row(@rsUsers,1),"LO_NMLS_Number__c")
  Set @LOStreet = Field(Row(@rsUsers,1),"Street")
  Set @LOCity = Field(Row(@rsUsers,1),"City")
  Set @LOState = Field(Row(@rsUsers,1),"State")
  Set @LOPostalCode = Field(Row(@rsUsers,1),"PostalCode")
  Set @LOPhone = Field(Row(@rsUsers,1),"Phone")
  Set @LOMobilePhone = Field(Row(@rsUsers,1),"MobilePhone")
  Set @LOFax = Field(Row(@rsUsers,1),"Fax")
  Set @LOEmail = Field(Row(@rsUsers,1),"Email")
  Set @LO_Branch_URL = Field(Row(@rsUsers,1),"LO_Branch_URL__c")
  Set @LOBranch_NMLS_Number = Field(Row(@rsUsers,1),"Branch_NMLS_Number__c")
  Set @LO_Photo = Field(Row(@rsUsers,1),"CC_PhotoURL__c")

 EndIf 

 If Not Empty (@LOBranch_NMLS_Number) Then

  Set @LOTeamName = Lookup("BranchWebsite", "BranchTeamName_Override__c", "Branch_NMLS_Number__c", @LOBranch_NMLS_Number)

 endif

EndIf
]%%

Best Answer

Perhaps the field actually has a Null value instead of EMPTY. AMPscript doesn't evaluate for NULL when it's comparing against an attribute.

To get around this try:

IF @LOBranch_NMLS_Number != "" or @LOBranch_NMLS_Number is NOT NULL THEN
Related Topic