0

I'm using some ampscript to set a variable to pull record information in from a Data Extension based on their contactKey. I've done this several times before (different marketing cloud instance).

/* Get the key */
set @subKey = AttributeValue("_subscriberkey")
/*if empty, pull from different param in URL*/
if empty(@subKey) then set @subKey = AttributeValue("sk") endif
/*if empty, pull from form field*/
if empty(@subKey) then set @subKey = requestparameter("_subscriberkey")  endif

The 1st one is based on the qs code generated from an email (truest form) The 2nd should pull from the URL parameter (ie. whatever.com/preference?sk=123) <-- this is the one that I utilize for testing since I can just write in a matching contactKey.

I can't seem to even get the page to populate a personalization string for testing on the second option.

Using this: Test: %%=v(@subKey)=%%

Even if I strip out ALL other ampscript block code to just this:

/*if empty, pull from different param in URL*/
set @subKey = AttributeValue("sk")

I can't get it to populate. Did something change with Marketing Cloud's handling of URL parameters? I'll add that this page is not secure (no SSL cert) - but even still, I've done this without a secure page before.

  • Do I need PURLs enabled as a business rule? – Tom Callahan Mar 17 '19 at 21:47
  • Swapped out if empty(@subKey) then set @subKey = AttributeValue("sk") endif with if empty(@subKey) then set @subKey = requestparameter("sk") endif . It appears to be functioning...odd that using the AttributeValue works in all my other instances – Tom Callahan Mar 17 '19 at 21:51
  • use QueryParameter instead of requestparameter – pkharries Mar 18 '19 at 6:23
3

AttributeValue() only works on attributes passed in from sending DE/All Subs/passed values in TriggeredSendDefinition - It does not pull from a URL or form post. Which is why it is returning null when you try to pull your 'sk' value as it does not exist in any of the above contexts.

You need to use RequestParameter() or QueryParameters() to gather anything passed as a parameter string.

RequestParameter() can be used to retrieve form values from both a GET and a POST method. (including manual parameters added to your URL)

QueryParameters() can only be used on GET method, or values actually appended manually and shown on the displayed URL.

I tend to default to RequestParameter() due to its versatility - but in your case, either one should solve your issue.

Final Code:

/* Get the key */
set @subKey = AttributeValue("_subscriberkey")
/*if empty, pull from different param in URL*/
if empty(@subKey) then set @subKey = requestparameter("sk") endif
/*if empty, pull from form field*/
if empty(@subKey) then set @subKey = requestparameter("_subscriberkey")  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.