I have a data extension that contains customers along with a category. In my html content, I want to add the category for the customer IF the customer_id can be found within that data extension. If it can't be found in the data extension then to handle this with default category. To do this I'm using LookupRows. My code and the links work within SF preview and test function but when the email is sent to my inbox and I click on the link in my inbox, it leads to a page with the below error. I've also tried personalisation string, to use redirect only but it doesn't work.


An error has occurred and has been logged by our system. Thank you.

Here is my FINAL working code:


  VAR @category_name_look_up, @category_link_look_up, @category_url_tracked, @rows, @row, @rowCount, @customer_id

  SET @category_name_look_up = Lookup("Customer Data Extension", "category", "customer_id", customer_id)
  SET @category_link_look_up = Lookup("Customer Data Extension", "category_link", "customer_id", customer_id)
  SET @category_url_tracked = CONCAT(@category_link_look_up,"?utm_source=salesforce&utm_campaign=&utm_term=marhead|default|01")

  SET @rows = LookupRows("Customer Data Extension","customer_id", @customer_id)
  SET @rowCount = rowcount(@rows)
  SET @customer_id = AttributeValue("customer_id")

  if @rowCount > 0 then


    <td align="center">
        <a href="%%=RedirectTo(@category_url_tracked)=%%">%%=v(@category_name_look_up)=%%</a>


    <td align="center">
        <a href="https://www.website.com/shop/this_category?utm_source=salesforce&utm_campaign=&utm_term=marhead|default|01">This Category</a>

  • what is the "TreatAsContent" intended for? Have you tried simply with %%=RedirectTo(@category_link_look_up)=%% ? May 26 at 12:07
  • Yes, it goes to a page with the same error.
    – T01
    May 26 at 13:15
  • are you sure you code is returning a URL in the lookup with the protocol http/s
    – EazyE
    May 26 at 14:00
  • Yep, the customer data extension contains the full https. It looks like my custom tracking is causing the issue. I've edited the message above to include this. I ran a test email removing the tracking and the link works. Is there a way to keep the tracking? The tracking isn't an issue on other emails so hoping there is a work around to this.
    – T01
    May 26 at 14:51

2 Answers 2


I think you have to build the entire url you want to redirectTo before calling the function.

Make the tracking params part of variable @category_link_look_up, then

<a href="%%=RedirectTo(@category_link_look_up)=%%">click</a>

(without TreatAsContent)


I am assuming the link you are pulling from the DE contains ampscript or personalization strings which is why you are using TreatAsContent. As @jonaslamberty said, you need to have the final url before using the redirectto

So I would recommend putting in a new var to CONCAT it together first, use the following instead:

SET @myUrl = CONCAT(TreatAsContent(@category_link_look_up),"?utm_source=salesforce&utm_campaign=&utm_term=marhead|default|01")

<a href="%%=RedirectTo(@myUrl)=%%">%%=v(@category_name_look_up)=%%</a>
  • Thanks both. I have tried the CONCAT - but this is the error that I keep on getting: Error 1: Invalid Function Call<br>The specified attribute or custom object field name was not found for this client. Function Call: RedirectTo(category_preferred_1_url) Attribute or Field Name: category_preferred_1_url <br>Invalid Content: <br>RedirectTo(category_preferred_1_url)
    – T01
    2 days ago
  • @T01 you need to add the @ in front of category_preferred_1_url as without it, it is looking for that as a personalization string (column in the sendalbe data) instead of from an AMPscript variable. So should try RedirectTo(@category_preferred_1_url) instead. 2 days ago
  • Ah yes! Totally missed that. This now works. Thank you all for your help. I've updated my code above with the corrections and additions.
    – T01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .