0

I have a cloud page with form where I collect some data into DE. I have to use automation to update Contact id if same email exists in SF if not I have to create contact and populate the DE. I have written ampscript to content but I check it in cloudpage. then I will call the script via ssjs to automation. I have a currently these fields in my DE.SubscriberKey EmailAddress FirstName LastName Study_Program_Type Date_time ContactId Program_Duration is_proceed.

AND CODE FOR CLOUDPAGE(CONTENT)

var @email, @subscriberRows, @rowCount, @ContactId

/*use a different identifier to make sure you retrieve all unprocessed recrods*/
set @subscriberRows = LookupRows("TriggeredSend","is_proceed", "False")

/*after you rectrieved all unprocessed records you need to run through all of them by using LOOP if you got more records than 0*/

/*in the loop you can check if each record has a contact in sf with the same email address, if yes - then just get contact ID. If NOT - create a new contact*/
/*if the record in de was proccessed you can change identifier value so that in the future automation run you don't look at it again*/

if RowCount(@subscriberRows) > 0 then
 
 for @i = 1 to RowCount(@SubscriberRows) do 
        var @firstName, @lastName, @programType, @ProgramDuration
        Set @email = Field(Row(@subscriberRows, @i), "EmailAddress")
        Set @firstName = Field(Row(@subscriberRows, @i), "FirstName")
        Set @lastName = Field(Row(@subscriberRows, @i), "LastName")
        Set @programType = Field(Row(@subscriberRows, @i), "Study_Program_Type")
        Set @ProgramDuration = Field(Row(@subscriberRows, @i), "Program_Duration")
        
        
        SET @existingContactRows = RetrieveSalesforceObjects(
        "Contact",
        "Id",
        "Email", "=", @email
    )

    if RowCount(@existingContactRows) == 1 then
        SET @existingContactRow = Row(@existingContactRows, 1)
        SET @existingContactId = Field(@existingContactRow, "Id")
      SET @updateResult = UpdateSingleSalesforceObject(
         "Contact",
          @existingContactId,
         'FirstName', @firstName,
         'LastName', @lastName,
         'Email', @email,
         'Study_Program_Type__c', @programType,
         'Program_Duration__c', @ProgramDuration
     )
    UpdateDE("TriggeredSend",1, "EmailAddress", @email, "ContactId", @existingContactId,"is_proceed", "True")


    ELSE
   
        SET @createResult = CreateSalesforceObject(
            "Contact",
            5,
            'FirstName', @firstName,
            'LastName', @lastName,
            'Email', @email,
            'Study_Program_Type__c', @programType,
            'Program_Duration__c', @ProgramDuration
        )
        
         SET @createdContactId = Field(@createResult, "Id")
           UpdateData("TriggeredSend",1, "EmailAddress", @email, "ContactId", @createdContactId, "FirstName", @firstName, "LastName", @lastName, "Study_Program_Type", @programType, "Program_Duration", @ProgramDuration,"is_proceed", "True")


    endif
next @i
endif
]%%


<p>@existingContactRows:  %%=V(@existingContactRows)=%%</p>
<p>@createResult: %%=V(@createResult)=%%</p>
<p>@subscriberRows: %%=V(@subscriberRows)=%%</p>
<p>@lastName: %%=V(@lastName)=%%</p>
<p>@email: %%=V(@email)=%%</p>
<p>@programType: %%=V(@programType)=%%</p>

BUT I GET Error Message: "Invalid object property name. Object Type: System.String Property Name: Id"

Description: "System.Exception: Invalid object property name. Object Type: System.String Property Name: Id - from Jint "

IN contact object id is defined like "Id" . Do you know why?

1 Answer 1

0

@createResult is not a row, but simply the ID itself. So the value of @createResult is already 0036F00001APnymUAD. You don't need to request the ID from the variable and pass it on to @createdContactId.

1

You must log in to answer this question.

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