Forked from wvpv/sfmc-ampscript-upsert-data-extension-row.amp
Created
January 27, 2017 05:22
-
-
Save katydorjee/92240b80c595d9854e2711cce33724bd to your computer and use it in GitHub Desktop.
SFMC AMPScript Upsert/UpdateAdd Data Extension Row
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%[ | |
VAR @deObj, @prop, @de_statusCode, @de_statusMsg, @errorCode | |
var @FirstName, @LastName, @Email, @SubscriberKey | |
set @FirstName = RequestParameter("FirstName") | |
set @LastName = RequestParameter("LastName") | |
set @Email = RequestParameter("Email") | |
set @SubscriberKey = RequestParameter("SubscriberKey") | |
/* for debugging */ | |
outputline(concat("<br>@FirstName: ",@FirstName,"")) | |
outputline(concat("<br>@LastName: ",@LastName,"")) | |
outputline(concat("<br>@Email: ",@Email,"")) | |
outputline(concat("<br>@SubscriberKey: ",@SubscriberKey,"")) | |
SET @deObj = CreateObject("DataExtensionObject") | |
SetObjectProperty(@deObj, "CustomerKey", "TestDataExtension") | |
IF NOT empty(@FirstName) THEN | |
SET @prop = CreateObject("APIProperty") | |
SetObjectProperty(@prop, "Name", "FirstName") | |
SetObjectProperty(@prop, "Value", @FirstName) | |
AddObjectArrayItem(@deObj, "Properties", @prop) | |
ENDIF | |
IF NOT empty(@LastName) THEN | |
SET @prop = CreateObject("APIProperty") | |
SetObjectProperty(@prop, "Name", "LastName") | |
SetObjectProperty(@prop, "Value", @LastName) | |
AddObjectArrayItem(@deObj, "Properties", @prop) | |
ENDIF | |
IF NOT empty(@email) THEN | |
SET @prop = CreateObject("APIProperty") | |
SetObjectProperty(@prop, "Name", "Email") | |
SetObjectProperty(@prop, "Value", @email) | |
AddObjectArrayItem(@deObj, "Properties", @prop) | |
ENDIF | |
IF NOT empty(@SubscriberKey) THEN | |
SET @prop = CreateObject("APIProperty") | |
SetObjectProperty(@prop, "Name", "SubscriberKey") | |
SetObjectProperty(@prop, "Value", @SubscriberKey) | |
AddObjectArrayItem(@deObj, "Properties", @prop) | |
ENDIF | |
SET @updateOptions = CreateObject("UpdateOptions") | |
SET @saveOptions = CreateObject("SaveOption") | |
SetObjectProperty(@saveOptions, "SaveAction", "UpdateAdd") | |
SetObjectProperty(@saveOptions, "PropertyName", "*") | |
AddObjectArrayItem(@updateOptions, "SaveOptions", @saveOptions) | |
var @options | |
SET @de_statusCode = InvokeUpdate(@deObj, @de_statusMsg, @errorCode, @updateOptions) | |
outputline(concat("<br>@de_statusCode: ",@de_statusCode,"")) | |
outputline(concat("<br>@de_statusMsg: ",@de_statusMsg,"")) | |
outputline(concat("<br>@errorCode: ",@errorCode,"")) | |
IF @de_statusCode != "OK" THEN | |
RaiseError(@de_statusMsg, 0, @de_statusCode, @errorCode) | |
ENDIF | |
]%% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment