2

I am trying to create a new record on a salesforce custom object for storing survey responses.

I am sending the Name (full name) to the cloud page via AMPscript in an email link. Here is the cloudpage relevant code:

%%[

var @fullName /* from the email AMP */
set @fullName = RequestParameter('fullName')
var @rating, @explain, @createDERecord, @createdDate
set @name = 'New Client Survey'
set @rating = RequestParameter('rating')
set @explain = RequestParameter('explain')
set @createdDate = Replace(FormatDate(Now(),"yyyy-MM-ddT","hh:mm:ss"),' ','')

if RequestParameter("submitted") == "submitted" then

 set @surveyObject = CreateSalesforceObject('Pesquisa_Satisfacao__c',5,'Data_Resposta_Pesquisa__c', @createdDate, 'Nota_Atribuida_pelo_Cliente__c',@rating, 'Comentarios__c', @explain,'Contato_Relacionado__c',@fullName, 'Name', @name)

endif

]%%

I also outputted the @fullName to make sure it was retrieving correctly and this is not the problem.

The custom object is linked to the Contact Object in the Sales Cloud. I suspect that the problem is with the datatypes in the Sales Cloud:

They are all text except for the 'Data Resposta Pesquisa' which is a date type and the 'Contato Relacionado' which is a lookup(contact) type - it looks up the contacts based on the name.

When I submit my cloudpage form it gives me a 500 error. How can I fix this?

Attached is a screenshot of the sales cloud:

Fields for Custom Object

UPDATE:

After running the javascript, this is what popped up @CodeRage:

{"message":"Call to create the salesforceobject Pesquisa_Satisfacao__c failed! Error status code: INVALID_FIELD_FOR_INSERT_UPDATE\nError message: Pesquisa_Satisfacao__c: bad field names on insert/update call: Contato_Relacionado__c","description":"ExactTarget.OMM.FunctionExecutionException: Call to create the salesforceobject Pesquisa_Satisfacao__c failed! Error status code: INVALID_FIELD_FOR_INSERT_UPDATE\nError message: Pesquisa_Satisfacao__c: bad field names on insert/update call: Contato_Relacionado__c\r\n Error Code: CREATESFOJBECT_FUNC_ERROR\r\n - from Jint\r\n\r\n"}

UPDATE 2:

I removed all the CSS and cleaned up my code and added the RetrieveSalesforceObjects command. I am attaching my entire code because the error I found did not make any sense and did not look like AMPscript:

<meta charset="utf-8">
  <h1>Customer Satisfaction Survey</h1>
  <br><br><br>
  <form action="%%=RequestParameter('PAGEURL')=%%" method="post">


<br><br>
   How would you rate the services you have received from Gaveteiro (5 being excellent)?<span class="error"></span><br><br>


   <label class="container">1<input type="radio" name="rating" value="1"><span class="radio">
    </span>
   </label>

   <label class="container">2<input type="radio" name="rating" value="2"><span class="radio"></span>
   </label>

   <label class="container">3<input type="radio" name="rating" value="3"><span class="radio"></span>
   </label>

   <label class="container">4<input type="radio" name="rating" value="4"><span class="radio"></span>
   </label>

   <label class="container">5<input type="radio" name="rating" value="5"><span class="radio"></span>
   </label>

   <br><br><br>

   <label for="explain">
   Explain:<br><br>

   <textarea name="explain" id="explain" placeholder="Write your comments here"></textarea>
   <br><br>

   <input id="submitted" type="hidden" name="submitted" value="submitted">

   <button type="submit" name="submit">Submit</button>




   <br><br><br><br><br>

  <script runat="server">
  Platform.Load("Core","1.1.1");
  try{
</script>
%%[

var @rating, @explain, @createDERecord, @createdDate, @key
set @key = RequestParameter('key')
set @name = 'New Client Survey'
set @rating = RequestParameter('rating')
set @explain = RequestParameter('explain')
set @createdDate = FormatDate(Now(),"iso") 
set @lookupVal = RetrieveSalesforceObjects('Contact','Name','Contact_Id_18__c','=',@key)

if RequestParameter("submitted") == "submitted" then
 set @surveyObject = CreateSalesforceObject('Pesquisa_Satisfacao__c',5,'Data_Resposta_Pesquisa__c', @createdDate, 'Nota_Atribuida_pelo_Cliente__c',@rating, 'Comentarios__c', @explain,'Contato_Relacionado__c',@lookupVal, 'Name', @name)

endif

]%%
<script runat="server">
  }catch(e){
    Write(Stringify(e));
  }
</script>
  %%=v(@key)=%%
  %%=IIF(RequestParameter("submitted") == "submitted", '<p>Your form has been submitted.</p>','')=%%


  </label></form>

Tried it again and this is what my console looks like in chrome:

Error

Not really sure what that error is. I verified all the API names, changed the API name to the object name for the custom object, still does not work. I am not getting any output from the javascript this time, but there are still no records in the Sales Cloud. When I submit my form it gives me the form submitted message btw.

RESULT:

Here is an explanation of how this issue was fixed and of all the steps I used.

  1. Create custom object in the Sales Cloud with a lookup field to match to a contact (This was done by our sales team so I can't explain the exact steps)
  2. Journey Builder using an update in status to indicate a new client.
  3. Email within the journey with a link to the cloudpage with AMPscript code to pass the Contact:Id:
%%[
var @key
set @key = AttributeValue('Contact:Id')
]%%
<p><a title="MyPage" href="%%=RedirectTo(CloudPagesURL(1711,'key',@key))=%%" alias="Survey" conversion="false">Take Our Survey</a></p>


Best,
<br>
Intern
  1. Cloudpage with survey and AMPscript:
%%[

var @rating, @explain, @createDERecord, @createdDate, @key
set @key = RequestParameter('key')
set @name = 'New Client Survey'
set @rating = RequestParameter('rating')
set @explain = RequestParameter('explain')
set @createdDate = FormatDate(Now(),"iso") 

if RequestParameter("submitted") == "submitted" then
    set @surveyObject = CreateSalesforceObject('Pesquisa_Satisfacao__c',5,'Data_Resposta_Pesquisa__c', @createdDate, 'Nota_Atribuida_pelo_Cliente__c',@rating, 'Comentarios__c', @explain,'Contato_Relacionado__c',@key, 'Name', @name)

endif

]%%

Used all the API names from the custom object and there was a field which was standard and the API name was just Name.

The parameter requests are from the html form and the key comes from the email link which is the contact id. You must pass the contact id in order for this to work as illustrated in the answers below.

Hope this helps someone.

| improve this question | | | | |
  • That console error gave by chrome is not related to AMPScript or even SSJS. You are fine with this. Basically, it happens because you need to include an icon to your cloud page. – Darleison Rodrigues Jan 17 at 11:42
1

First of all, for proper debugging, wrap your ampscript in a try/catch SSJS, and let us know what is says:

<script runat="server">
  Platform.Load("Core","1.1.1");
  try{
</script>

%%[ YOUR AMPSCRIPT CODE  ]%%

<script runat="server">
  }catch(e){
    Write(Stringify(e));
  }
</script>

You can also try to format your date correctly for Sales Cloud - this usually solves a lot of problems:

FormatDate(Now(),"iso") 

If this doesn't help, the problem might be in the lookup(contact) type field - you could try to retrieve the ID of the record first, using RetrieveSalesforceObjects and then pass the ID instead of looking up the full name.

| improve this answer | | | | |
1

The problem is, that you try to fill a lookup-field with a string value. Instead you need to provide the Salesforce ContactId.

I know this sounds disturbing as in Sales Cloud you can enter plain text and are able to select the correct record, however when interacting via API (or in that case AMPscript) you need to supply Salesforce IDs for lookup fields.

| improve this answer | | | | |

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.