Quantcast
Channel: Active questions tagged ampscript - Salesforce Stack Exchange
Viewing all articles
Browse latest Browse all 359

Partial/nonexact matches with LookupRows function

$
0
0

THE PROBLEM: LookupRows appears to be making partial matches of the third parameter (value used to match rows to return) and therefore returning the incorrect value.

BACKGROUND: Because of different data sources, we sometimes have users whose profile contains a "Country" value with the full country name (e.g., France, United States, Hong Kong), and other times with a two-letter ISO country code (e.g., FR, US, HK). The rest are simply blank. All of them should be the two-letter country code, so I usually include a short AMPScript (see below) to retrieve the two-letter codes when the subscriber profile contains a full country name.

Each country has a list of promotional content types that it can and cannot receive. For example, only the US, Canada, Australia, and Hong Kong can receive certain Sale promotions. The country names, their ISO codes, and the promotion eligibility (TRUE/FALSE) for each of 10 content types is all stored in a non-sendable data extension.

CODE: The AMPScript simply determines whether a country code or country name can be found in the DE and then sets the @country variable to the country code when found. For empty and invalid values, the value defaults to 'US'.

%%[VAR @country_input, @countrySET @country_input = CountryIF Empty(@country_input) THEN    SET @country = 'US'ELSEIF RowCount(LookupRows('international_footer_specs', 'Country Code', @country_input)) > 0 THEN    SET @country = Lookup('international_footer_specs', 'Country Code', 'Country Code', @country_input)ELSEIF RowCount(LookupRows('international_footer_specs', 'Country Name', @country_input)) > 0 THEN    SET @country = Lookup('international_footer_specs', 'Country Code', 'Country Name', @country_input)ELSE    SET @country = 'US'ENDIFIF @country == 'US' OR @country == 'CA' OR @country == 'AU' OR @country == 'HK' THEN]%%    %%=ContentAreaByName(Concat('My Contents\Dynamic\', emailname_))=%%%%[ENDIF]%%

The problem arises in the first 'ELSEIF'. If a user's country value is 'Austria', then it will match to 'AU' (which is the code for Australia). Similarly, 'Estonia' matches to 'ES' (which is the code for Spain).

It appears that the LookupRows function is making partial matches because the function does the matching "in reverse". That is, the function evaluates to 'TRUE' if the lookup value (e.g., 'Austria'), contains the entirety of the value stored in the DE (not the other way around). So, since 'AU' is contained within 'Austria', and 'ES' is contained within 'Estonia', this function will return those respective rows for each of those lookup values even though this should be evaluating to 'FALSE'.

BUG?: I would expect that it should be determining whether 'Austria' is contained within 'AU', not the other way around. After all, 'Austria' is the lookup value, not the value being matched against. Perhaps I'm misunderstanding the documentation, but this seems to be how it should work.

TEMPORARY SOLUTION: In my case, I can avoid this scenario by switching the two 'ELSEIF' statements, which allows the country names to be searched first, which in turn avoids the pitfall of erroneously matching partial strings (i.e., the country codes) to the lookup value. However, there are certainly instances where this could fail as well. For example, a lookup value of 'South Sudan' or 'Nigeria' would incorrectly match to 'Sudan' or 'Niger', respectively, if those countries existed within the data extension where I store country information.


Viewing all articles
Browse latest Browse all 359

Trending Articles