LoginSignup
0
0

AMPScriptのサンプル1

Last updated at Posted at 2023-05-07

まとめページに戻る
まとめA~M

Cloudpage を使用して電子メールからアンケートの回答を取得し、1 つの DE を電子メール アドレスとサブスクライバー キーと共に回答で更新しようとしています。

調査リンク: CloudPagesURL 関数は、電子メール アドレス、サブスクライバー キー、および元の電子メール送信に含まれるその他の属性を含む暗号化されたクエリ文字列を自動的に追加します。したがって、メールアドレスとサブスクライバーキーを関数の追加パラメーターとして指定する必要はありません。リンクを作成する正しい方法は次のとおりです。

href="%%=RedirectTo(CloudPagesURL(1866))=%%"

調査回答のキャプチャ Cloudpage:コードを次のように書き直します。

%%[
 set @Email = AttributeValue("emailaddr")
 set @SubscriberKey = AttributeValue("_subscriberkey")
]%%
<h2>HCP Survey</h2>
<form method="POST" action="%%=RedirectTo(CloudPagesURL(1849))=%%">
 <label for="Q1" required="Yes">Do you like pets? </label><br>
 <input type="radio" id="Yes" name="q1response" value="Yes" checked />
 <label for="Yes">Yes</label><br>
 <input type="radio" id="No" name="q1response" value="No" />
 <label for="No">No</label><br><br>
 <input type="submit" value="Submit" align="left" style="background: #FA6E40; border: none; color: #fff; font-family: Montserrat, Arial; font-weight: 700; text-decoration: none; width: 140px; height: 46px; font-size: 14px; text-align: center; padding: 0; cursor: pointer; " />
 </form>

いくつかの点に注意してください:

  • AttributeValue 関数を使用して、暗号化されたクエリ文字列から電子メール アドレスと購読者キーを取得します。
  • フォームに POST メソッドを指定しました
  • フォーム アクションは次のクラウド ページです
  • オプションが選択されていないフォームの送信を避けるために、Yes 要素にchecked属性を追加しました
  • フォームに送信ボタンを含めました

データエクステンションと調査キャプチャ確認クラウドページの更新:

私はあなたのコードを次のように書き直します:

%%[
 var @responsetime, @question1response
 set @Emailaddress = AttributeValue("emailaddr")
 set @SubscriberKey = AttributeValue("_subscriberkey")
 set @responsetime = SystemDateToLocalDate(NOW())
 set @question1response = RequestParameter("q1response")
 set @updateDE = "testsurveyresponsesde"
 InsertData(@updateDE, 
            "SubscriberKey", @subscriberKey, 
            "EmailAddress", @Emailaddress, 
            "responsetime", @responsetime,
            "question1_response", @question1response)
]%%

次の点に注意してください。

  • もう一度 AttributeValue 関数を使用して、暗号化されたクエリ文字列から電子メール アドレスと購読者キーを取得します。
  • RequestParameter 関数を使用して、フォームから応答を取得します
  • InsertData を使用してデータエクステンションに書き込みます。InsertData はクラウド ページで機能し、InsertDE は電子メールでのみ機能することに注意してください。ページを公開すると、InsertData に関連するエラーが発生します。エラーを無視してページを公開すると、機能します。

FormatDate

%%[
SET @MaturityDate = AttributeValue('Maturity Date__c') 
IF Empty(@MaturityDate) THEN 
    SET @MaturityDate1 = '' 
ELSE  
    SET @MaturityDate1 = Concat('Maturity Date: ', FormatDate(@MaturityDate, 's')) 
ENDIF 
]%% 
%%=v(@MaturityDate1)=%%

エラー

Error Message: "An error occurred when attempting to execute an UpsertData function call. See inner exception for details."Description: "ExactTarget.OMM.FunctionExecutionException: An error occurred when attempting to execute an UpsertData function call. See inner exception for details. Error Code: OMM_FUNC_EXEC_ERROR - from Jint --> --- inner exception 1--- ExactTarget.OMM.FunctionExecutionException: UpsertData Function is not valid in content. This function is only allowed in a non batch context. Function: UpsertData( @dataExtensionName, 1, "email", @email, "rewards-email", @rewardsEmail, "rewards-sms", @rewardsSMS, "newsletter-email", @newsletterEmail, "newsletter-sms", @newsletterSMS ) Error Code: OMM_FUNC_CONTEXT_ERR - from OMMCommon "

Everything you reference in AMPscript needs to be spelled correctly otherwise you'll get these types of errors.

Error while executing UpsertData() function

upsertData Function is not valid in content. This function is only allowed in a non batch context. Function: upsertData
https://salesforce.stackexchange.com/questions/117483/error-while-executing-upsertdata-function

"description": "ExactTarget.OMM.FunctionExecutionException: An error occurred when attempting to evaluate an HTTPPost function call. See the inner exception for details.\r\n Error Code: OMM_FUNC_EXEC_ERROR\r\n - from Jint --> \r\n\r\n --- inner exception 1---\r\n\r\nSystem.Net.WebException: The remote server returned an error: (401) Unauthorized. - from System\r\n\r\n\r\n\r\n"}

コードにデバッグ手順を追加してみてください。どのようなデータが取得されているかを理解するために、コードを変更してループ内にログを含めます。

PDF

その他

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0