我正在使用 Marketing Cloud Cloud 页面将联系人/潜在客户记录从数据扩展同步到相应的 Sales Cloud 活动(作为活动成员)。这部分运作良好。但是,当我尝试使用 InsertData 函数将信息写入数据扩展时收到错误消息。将 InsertData 函数添加到代码中时出现以下错误。
这是我的 InsertData 代码:
InsertData('SubscriptionSyncLog',
'SyncTime', @localTime,
'UniqueId', @uniqueId,
'LookupValue', @rowValue,
'SubscriptionId', @subscriptionId,
'CampaignId', @campaignId,
'Message', @outcome
)
这是整个云页面代码:
<!---------------------DEBUGGING SCRIPT START--------------------->
<script runat="server" type="text/javascript">
Platform.Load("core","1");
try {
</script>
<!---------------------------AMPSCRIPT---------------------------->
%%[
/*---------------------------SYNC RECORDS ISSUBSCRIBED = TRUE---------------------------*/
/**************SC CAMPAIGN, DE AND ROWS TO LOOK UP*******************/
var @rows, @row, @rowCount, @i, @subCentreDE, @rowValue, @columnValue, @campaignMemberId, @localTime
set @subCentreDE = "ChosenSubscription" /* DE to look for */
set @columnValue = "IsSubscribed" /* DE column to look for */
set @rowValue = "True" /* DE row value to look for */
set @rows = LookupOrderedRows(@subCentreDE,3000,"Email Asc",@columnValue,@rowValue)
set @rowCount = rowcount(@rows) /* Count the total rows found */
output(concat("<br>Row,Outcome,CampaignMemberId,Email,UniqueId,Record Type,SubscriptionId,CampaignId,IsSubscribed,Date Synced"))
/*******************CHECK IF ROWS ARE FOUND***************************/
if @rowCount > 0 then
/*************************ROWS FOUND***********************************/
/*****ADD EACH RECORD FROM THE DE TO THE SC CAMPAIGN IF NOT FOUND******/
for @i = 1 to @rowCount do
var @email, @uniqueId, @idField, @campaignMemberRow, @campaignMemberRows, @subscriptionId, @campaignId, @outcome
set @row = row(@rows, @i) /* get row based on counter */
set @email = field(@row,"email")
set @uniqueId = field(@row,"uniqueId")
set @subscriptionId = field(@row,"subscriptionId")
/***************MAP SUBSCRIPTION ID TO SC CAMPAIGN ID******************/
set @rows2 = LookupRows('Subscription','SubscriptionId',@subscriptionId)
set @rowCount2 = rowcount(@rows2) /* Count the total rows found */
if @rowCount > 0 then
set @row2 = row(@rows2, 1)
set @campaignId = field(@row2,"CampaignId")
endif
if not empty(@uniqueId) then
/************IDENTIFY IF THE RECORD IS A CONTACT OR LEAD***************/
if Substring(@uniqueId, 1,3) == "00Q" then
set @idField = "LeadId"
elseif Substring(@uniqueId, 1,3) == "003" then
set @idField = "ContactId"
else
set @idField = "invalid"
output(concat("<br>Invalid @uniqueId: ", @uniqueId))
endif
/*********CHECK IF THE UNIQUE ID AND CAMPAIGN ID IS VALID************/
set @outcome = "Invalid uniqueId or no campaignId mapped to subscription. Check the DE named: Subscription"
if @idField != "invalid" and (not empty(@campaignId)) then
/******************SEARCH FOR RECORD IN CAMPAIGN*********************/
var @campaignMemberStatus
set @campaignMemberRows = RetrieveSalesforceObjects('CampaignMember', "Id, Status", 'CampaignId', '=', @campaignId, @idField, "=", @uniqueId)
/***********************CHECK IF RECORD FOUND**************************/
if RowCount(@campaignMemberRows) == 0 then
/****************RECORD NOT FOUND, ADD TO CAMPAIGN*******************/
set @campaignMemberId = CreateSalesforceObject(
'CampaignMember', 3,
'CampaignId', @campaignId,
@idField, @uniqueId,
'Status','Subscribed'
)
set @localTime = DateAdd(NOW(), 19, "H")
set @outcome = "Added campaign member with status: Subscribed"
elseif RowCount(@campaignMemberRows) > 0 then
/*************RECORD FOUND, CHECK CAMPAIGN MEMBER STATUS*************/
set @campaignMemberRow = Row(@campaignMemberRows, 1)
set @campaignMemberId = Field(@campaignMemberRow, "Id")
set @campaignMemberStatus = Field(@campaignMemberRow, "Status")
if @campaignMemberStatus != "Subscribed" then
/*************UPDATE CAMPAIGN MEMBER STATUS TO SUBSCRIBED************/
UpdateSingleSalesforceObject('CampaignMember', @campaignMemberId, 'Status', 'Subscribed')
set @localTime = DateAdd(NOW(), 19, "H")*/
set @outcome = "Updated campaign member with status: Subscribed"
else
/**************CAMPAIGN MEMBER STATUS ALREADY SUBSCRIBED*************/
set @localTime = DateAdd(NOW(), 19, "H")
set @outcome = "Skipped - campaign member up to date"
endif
endif
endif
endif
/***************WRITE TO PROCESS LOGGING DATA EXTENSION**************/
InsertData('SubscriptionSyncLog',
'SyncTime', @localTime,
'UniqueId', @uniqueId,
'LookupValue', @rowValue,
'SubscriptionId', @subscriptionId,
'CampaignId', @campaignId,
'Message', @outcome
)
]%%
<!------------------------DEBUGGING VALUES------------------------>
<br>%%=v(@i)=%%,%%=v(@outcome)=%%,%%=v(@campaignMemberId)=%%,%%=v(@email)=%%,%%=v(@uniqueId)=%%,%%=v(@idField)=%%,%%=v(@subscriptionId)=%%,%%=v(@campaignId)=%%,%%=v(@rowValue)=%%,%%=v(@localTime)=%%
%%[ next @i ]%%
%%[ else ]%%
No rows found
%%[ endif ]%%
<!----------------------DEBUGGING SCRIPT END---------------------->
<script runat="server">
}catch(e){
Write(Stringify(e));
}
</script>
谢谢!!