0

I'm pulling a variable from the url to pass into a DE that is storing "opt-outs" for specific messaging.

I can print the variable on my cloud page and the data all seems to be flowing properly. I just can't seem to get the records to pass into the DE. I'm using this code on the cloudpage:

%%[
SET @id = QueryParameter("id")
IF @id is not null THEN
InsertDE("DEname","Id",@id)
ELSE
ENDIF
]%%

The DE is set-up properly with primary key and then nullable fields for everything else. Not sure why it won't pass the data into it though. Any ideas on what I might be doing wrong?

3 Answers 3

2

You are using IS NOT NULL in your conditional which is not viable in AMPScript conditional logic and likely always returning as false, skipping your Insert.

If you just want to see if it exists, you can use IF @id then which will see if @id exists/has a value and if it returns true, will display your conditions.

If you are looking to see if it is empty or null then you can use the EMPTY() or ISNULL() functions as well. e.g. IF NOT EMPTY(@id) then

Also, as @JohannesSchapdick stated, you are using the send time function InsertDE() which is only used inside an email at send time - you will instead want to use the InsertData() function on your cloud page.

A final note (opinion only) I usually recommend using RequestParameter() instead of QueryParameter() as Query will only return a value if the name/value is inside the displayed URL (e.g. Manual string append or GET) but RequestParameter() will also return a value if the name/value pair is passed in the header and not the displayed URL (e.g. via HTML POST). This is not a necessary change as it sounds like your value is coming in as an append string, not a POST - just a personal preference defensive coding recommendation.

My final recommended code would be:

%%[
  SET @id = QueryParameter("id") /* or SET @id = RequestParameter("id") */

  IF @id THEN

    InsertData("DEname","Id",@id)

  ENDIF
]%%
2
  • 2
    I would recommend this with the addition that you have to be aware of the interaction with InsertData and a primary key constraint in the target dataextension (as described in my post). Mar 28, 2019 at 14:21
  • This is awesome. I got it to work with the code, just needed to use IF NOT EMPTY for my use-case but it's now pulling the data into my DE. I will absorb as much as I can from both posts(Gortonington + Johannes) and learn when to use what function depending on need. Thank you for all the help. Mar 28, 2019 at 18:41
1

When you look at the description of the function it says that its for this purpose: Use this function with email messages at send time only Therefore you need a different function.

InsertData or UpsertData are the function you are searching for. What suits your case is depending on your exact aim.

I think that you might have not thought of: You told you have a primary key - i believe this id is the primary key. But when it comes to unsubscribes a person can unsubscribe and resubscribe. Now think of this scenario: What do you want to happen if someone unsubscribes and resubscribes and unsubscribes again?

What is supposed to happen when he resubscribes? What is supposed to happen with the datarecord in your table when a unsubscribe process takes place two times? Do you really need a primary key to "id" or do you rather need a unique constraint like "id" and "date" or do you even need any primary key? When you can answer these questions you know more about how you have to set up your dataextension and which function you have to use (UpsertData or InsertData).

2
  • no need to use InsertData function i mean InsertDE function also working then why you told use InsertData function ?
    – Ravi.A
    Mar 28, 2019 at 12:22
  • 1
    @pkharries - trying to use a send time function on a cloud page (if it doesn't error) will cause unexpected behavior - which is why there are 2 different functions for the same action. Mar 28, 2019 at 13:08
0

@McdonaldZip try like this

  this is landing page or cloud page
%%[

 Set @id= QueryParameter("id")

IF @id!='' THEN
 InsertDE("DEname","Id",@id)
 ENDIF
 ]%%
value:%%=v(@id)=%%
 ---------------------------
put link like this in Email template
  <html>
   <body>
   <p>
   <a title="MyPage" href="%%=MicrositeURL(24292, "id", 
   "test")=%%">passurl</a>
    </p>


  </body>
   </html>
3
  • if you use cloud page means Replace with MicrositeURL with CloudPagesURL
    – Ravi.A
    Mar 28, 2019 at 11:25
  • 1
    How does your answer differ from mine? I dont understand the extra benefit(tbh). [The owner of the question told the values are printed on the cloudpages therefore the link between email and cloudpage is working] Mar 28, 2019 at 12:16
  • 1
    @pkharries - please provide more details into HOW this answers the OP's question and also the WHY it works. Just posting code with 'try this' is not a learning experience for anyone, but instead just doing the work for the OP - which is not the purpose of this forum. Mar 28, 2019 at 13:29

You must log in to answer this question.

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