0

I am trying to prefill a SmartCapture form using AMPscript and I am not sure why it is not working.

In my org the API field Name for the contact Id is ContactId18digit__

Here is my code:

%%[

 VAR @subscriberkey, @email, @firstname, @lastname

 SET @subscriberkey = _subscriberkey

 IF NOT EMPTY(@subscriberkey) THEN

             SET @rs= RetrieveSalesforceObjects("Contact", "FirstName,LastName,Email", "ContactId18digit__", "=", @subscriberkey)

             SET @rowCount = rowcount(@rs)

             IF @rowCount > 0 THEN

                 SET @row = row(@rs,1)

                 SET @email = field(@row,"Email")

                 SET @firstname = field(@row,"FirstName")

                 SET @lastname = field(@row,"LastName")

             ENDIF

 ELSE

 SET @email = emailaddr

 SET @firstname = ""

 SET @lastname = ""

 ENDIF

 ]%%

Then within each of the Fields I set up the Value as follows:

<input type="text" id="FirstName" name="FirstName" data-field-type="Text" value="%%=v(@firstname)=%%" required="required" data-validation-message="Please fill out this field.">

Is there anything that I am missing?

Thanks in advance.

0

1 Answer 1

0

These personalization strings are only used in email, to use them in a cloudpage (smart capture form), you need to populate and get them through parameters.

Populate these parameters in email:

%%[

SET @subscriberkey = _subscriberkey

SET @email = emailaddr

SET @url = CloudPagesURL(Smart_Capture_Page_ID, "subKey", @subscriberkey, "emailAddress", @email)

]%%
<a href="%%=v(@url)=%%">Smart Capture Link</a>

Get parameters in the Smart Capture page:

Also the custom field should be ContactId18digit__c

%%[

 VAR @subscriberkey, @email, @firstname, @lastname

 SET @subscriberkey = RequestParameter("subKey")

 IF NOT EMPTY(@subscriberkey) THEN

             SET @rs= RetrieveSalesforceObjects("Contact", "FirstName,LastName,Email", "ContactId18digit__c", "=", @subscriberkey)

             SET @rowCount = rowcount(@rs)

             IF @rowCount > 0 THEN

                 SET @row = row(@rs,1)

                 SET @email = field(@row,"Email")

                 SET @firstname = field(@row,"FirstName")

                 SET @lastname = field(@row,"LastName")

             ENDIF

 ELSE

 SET @email = RequestParameter("emailAddress")

 SET @firstname = ""

 SET @lastname = ""

 ENDIF

 ]%%

References:

You must log in to answer this question.

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