0

I'm new to SFMC and learning AMPSCRIPT. I am getting the following error when previewing.

The subscriber preview failed to generate. Review the details, correct all issues, and try again.

There is an error in your email. Please contact your customer service representative.

Error 1: Script SET Statement Invalid<br>An error occurred when attempting to resolve a script expression. See inner exception for detail.

 Script Expression: [Contact:Id]
 MemberID: 7291454
 JobID: 0

The Journey Builder entry events primary object is Opportunity. I've tried setting the attribute to Opportunity:id. I then tried setting it to Contact: id. Both time I got errors.

Here is the AMPSCRIPT I'm using. Note: I didn't create it so I don't understand it fully. But, I'm trying to understand it. Any help is appreciated.

%%[
    /* AMPscript pulls in the values associated with Salesforce Object triggering the send */
    /* Fields will be populated by trigger data. RecordId = Contact ID in SFDC */
    /* Contact:Id column is used to determine the rest of the information to look up the Loan Officer info */

    SET @Id = [Contact:Id]
    SET @FirstName = [Contact:FirstName]
    SET @EmailAddress = [Contact:Email]

    SET @OwnerID = Lookup("Opportunity_Salesforce","OwnerId","Primary_Contact__c",@Id)
    SET @OwnerRow = RetrieveSalesforceObjects("User", "NMLSNumber__c, FirstName, Name, Phone, MobilePhone, Fax, Email, Bio_Link__c", "Id","=",@OwnerId)
    IF RowCount(@OwnerRow) > 0 THEN 
      SET @NMLSnumber = Field(Row(@OwnerRow,1),"NMLSNumber__c")
      SET @LOFirstName = Field(Row(@OwnerRow,1),"FirstName")
      SET @LOFullName = Field(Row(@OwnerRow,1),"Name")
      SET @LODirect = Field(Row(@OwnerRow,1),"Phone")
      SET @LOMobile = Field(Row(@OwnerRow,1),"MobilePhone")
      IF Length(@LOMobile) > 10 THEN
       SET @LOMobile = Substring(@LOMobile,4,10)
      ENDIF
      SET @LOFax = Field(Row(@OwnerRow,1),"Fax")
      SET @LOEmail = Field(Row(@OwnerRow,1),"Email")
      SET @LOBioLink = Field(Row(@OwnerRow,1),"Bio_Link__c")
    ELSE

    ENDIF

  ]%%
  • Your first 3 parameters are not called properly. They would have be in data extensions ( probably the event source) for you to call them. You can't call Salesforce objects directly like that. – Samuel Dare Jun 27 '17 at 18:21
  • Are you previewing from your triggered send data extension or something else? – Adam Spriggs Jun 27 '17 at 19:16
  • Hi Adam. Thanks for reaching out! I am previewing using the data extension related to the entry event in the program. – Mark Freestone Jun 27 '17 at 19:21
  • Hi Data_Kid. This is super helpful. I sensed that there was a problem with the first 3 parameters. If I understand your question correctly, ID, FirstName, EmailAddress need to live as attributes in the data extension. I have opportunity id. The others aren't there. – Mark Freestone Jun 27 '17 at 19:23
  • Here are the fields that are in the data extension. Opportunity:Primary_Contact__c,Opportunity:Primary_Contact__r:FirstName,Opportunity:Owner:FirstName,Opportunity:Primary_Contact__r:Email,Opportunity:Id,Opportunity:OwnerId – Mark Freestone Jun 27 '17 at 19:30
0

I had a look at the fields you provided and the discussion - I believe the following script should work, assuming the fields are the same.

%%[
    /* AMPscript pulls in the values associated with Salesforce Object triggering the send */
    /* Fields will be populated by trigger data. RecordId = Contact ID in SFDC */
    /* Contact:Id column is used to determine the rest of the information to look up the Loan Officer info */

    SET @OppId = [Opportunity:Id]
    SET @OwnerId = [Opportun‌​ity:OwnerId]
    SET @ContactId = [Opportunity:Primary_Contact__c
    SET @FirstName = [Opportunity:Primary_Contact__‌​r:FirstName]
    SET @EmailAddress = [Opportunity:Primary_‌​Contact__r:Email]

    SET @OwnerRow = RetrieveSalesforceObjects("User", "NMLSNumber__c, FirstName, Name, Phone, MobilePhone, Fax, Email, Bio_Link__c", "Id","=",@OwnerId)
    IF RowCount(@OwnerRow) > 0 THEN 
      SET @NMLSnumber = Field(Row(@OwnerRow,1),"NMLSNumber__c")
      SET @LOFirstName = Field(Row(@OwnerRow,1),"FirstName")
      SET @LOFullName = Field(Row(@OwnerRow,1),"Name")
      SET @LODirect = Field(Row(@OwnerRow,1),"Phone")
      SET @LOMobile = Field(Row(@OwnerRow,1),"MobilePhone")
      IF Length(@LOMobile) > 10 THEN
       SET @LOMobile = Substring(@LOMobile,4,10)
      ENDIF
      SET @LOFax = Field(Row(@OwnerRow,1),"Fax")
      SET @LOEmail = Field(Row(@OwnerRow,1),"Email")
      SET @LOBioLink = Field(Row(@OwnerRow,1),"Bio_Link__c")
    ELSE

    ENDIF

  ]%%
  • Thank you Kenneth. I'll post it into the HTML and see what happens. This is super helpful. – Mark Freestone Jun 30 '17 at 19:12
  • Let me know how it goes :) – Kenneth Wagner Jun 30 '17 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.