2

Are Data Extension variables merged before AMPScript is run? E.g. I want to see if a data extension variable for the current recipient contains part of a string:

%%[
var @result
SET @result = RegExMatch("A String", ".*(\|%%DATAEXT_VAR%%\|).*", 1)
IF Length(@result) > 0 THEN]%%
  ... show HTML here ...
%%[ ENDIF ]%%

This doesn't work. Does the regular expression need assembling using CONCAT, or the variable needs to be accessed via Field() or similar? I have not found documentation covering this.

0

I'd recommend not using raw send context variables. I generally check them first with the AttributeValue() function:

%%[
var @result, @regextouse, @data_ext_var

set @data_ext_var = AttributeValue("DATAEXT_VAR")

if not empty(@data_ext_var) then

    SET @regextouse = CONCAT(".*(\|", @data_ext_var, "\|).*")
    SET @result = RegExMatch("A String", @regextouse, 1)

    IF Length(@result) > 0 THEN
    ]%%
      ... show HTML here ...

    %%[ ENDIF ]%%

%%[ ENDIF ]%%

May not be a big deal in your case, but if there's any fluidity in the data extension columns, then it's a good idea. Many of the AMPScript functions don't handle null values very well. The AttributeValue() function returns an empty string in that case.

| improve this answer | |
1

Cracked it. You do need to use CONCAT:

%%[
var @result, @regextouse
SET @regextouse = CONCAT(".*(\|", DATAEXT_VAR, "\|).*")
SET @result = RegExMatch("A String", @regextouse, 1)
IF Length(@result) > 0 THEN]%%
  ... show HTML here ...
%%[ 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.