1

I am creating a cloudpage on web studio and using Radio Button to select the donation value to create a new opportunity (and a contact if not already exists) having the selected radio button donation value. There are a few static values and one is user input as a text. I checked in sales cloud, the Amount field type is currency (16,2) hence used FormatNumber as suggested on stackexchange. But the @amount is not getting picked up for the text input and throwing an error. Below is the code. Any clue on this would be appreciated.

https://jsfiddle.net/rohankulkarn/uvpngx7q/5/

Getting this error for Text Field:

{"message":"An error occurred when attempting to evaluate a FormatNumber function call. 
 See inner exception for details.
 Function Call: FormatNumber(RequestParameter(\"Amount\"),\"N2\")

 StackID: 11
 EnterpriseID: 110006382
 ClientID: 110006382
 Client Database ID: 11033
 Account Type: ENTERPRISE_2
 JobID: 0
 SubscriberID: 0
 Content Type: HTML
 MachineName: ATL1S11PGS001
","description":"ExactTarget.OMM.FunctionExecutionException: 
 An error occurred when attempting to evaluate a FormatNumber function call. 
 See inner exception for details.
 Function Call: FormatNumber(RequestParameter(\"Amount\"),\"N2\")

 StackID: 11
 EnterpriseID: 110006382
 ClientID: 110006382
 Client Database ID: 11033
 Account Type: ENTERPRISE_2
 JobID: 0
 SubscriberID: 0
 Content Type: HTML
 MachineName: ATL1S11PGS001
 Error Code: OMM_FUNC_EXEC_ERROR
 - from Jint --> 

 --- inner exception 1---

ExactTarget.OMM.FunctionExecutionException: 
An error occurred when attempting to evaluate a FormatNumber function call. 
The input value (on,55) cannot be formatted as a number. 
The first parameter value for a FormatNumber call must be a numeric type supported by the requested format.
 Value: on,55
 Format: N2
 Error Code: OMM_FUNC_EXEC_ERROR
 - from OMMCommon"
} 
7
  • 1
    Hi Rohan, does it work correctly when you use one of the pre-defined values (500, 1000)?
    – zuzannamj
    Oct 8 '19 at 13:33
  • getting this error for 1000 but strangely 500 and 250 worked correctly. {"message":"Call to create the salesforceobject Opportunity failed! Error in the application.","description":"ExactTarget.OMM.FunctionExecutionException: Call to create the salesforceobject Opportunity failed! Error in the application.\r\n Error Code: CREATESFOJBECT_FUNC_ERROR\r\n - from Jint\r\n\r\n"}. Updated the error message for Text Field in original question. Oct 8 '19 at 13:57
  • I had worked on another alternate code which worked fine for static buttons but no idea how this can be edited for text input. here it is jsfiddle.net/rohankulkarn/tjfa6k2w Oct 8 '19 at 14:05
  • Hello, I am following up to check if anyone has any idea on this issue? Oct 9 '19 at 5:56
  • 1
    Hi Rohan, I can see that a string on, is getting appended to the amount, but have no idea where it is coming from - as a dirty workaround you could use a Replace or Substring function, but it would be much better to find out how this string gets produced in the first place
    – zuzannamj
    Oct 9 '19 at 6:07
2

I was able to finally sort out where the on, was coming from, there were two problems with the form.

  1. The form was referencing "Amount" twice in the last line, once in the radio button and once in the text field and that's why it was expecting two values as an outcome, separated with a comma: <input type="radio" name="Amount"> $ <input type="number" name="Amount"><br>
  2. The default value for checkboxes and radio buttons is on. That is why the first value for the radio button was on, followed by a comma.

Here's the whole script, I also added some conditions for determining which amount was selected:

<script runat="server">
  Platform.Load("Core","1.1.1");
  try{
</script>
%%[
var @email, @firstName, @lastName, @retrievecontact, @ContactId, @opportunity, @date, @name, @amount, @freeAmount, @finalAmount


IF RequestParameter("submitted") == true THEN

set @email = QueryParameter("email")
set @firstName = RequestParameter("firstName") 
set @lastName = RequestParameter("lastName") 
set @email = RequestParameter("email") 
set @amount = RequestParameter("Amount")
set @freeAmount = RequestParameter("freeAmount")

 IF NOT EMPTY(@amount) THEN
 SET @finalAmount = FormatNumber(@amount, "N2", "en-US")
 ELSEIF NOT EMPTY(@freeAmount) THEN 
 SET @finalAmount = FormatNumber(@freeAmount, "N2", "en-US")
 ELSE 
 SET @finalAmount = FormatNumber(0, "N2", "en-US")
 ENDIF


set @date = FormatDate(Now(),"iso")
set @name = concat ("Donation - ", @date)


/* check if contact exists*/
set @retrievecontact = RetrieveSalesforceObjects('Contact','Id,Email','Email', '=', RequestParameter('email'))

IF RowCount(@retrievecontact) > 0 THEN

/* get Id if exists*/
set @ContactId = Field(Row(@retrievecontact, 1), 'Id')

ELSE

set @ContactId = CreateSalesforceObject('Contact', 3, 'FirstName', @firstName, 'LastName', @lastName, 'Email', @email)

ENDIF


/* create opportunity for either */
set @opportunity = CreateSalesforceObject('Opportunity', 6, 'Name', @name, 'Amount', @finalAmount, 'RecordTypeId', '0126C000000H9uvQAC', 'CloseDate', @date, 'StageName', 'Received','npsp__Primary_Contact__c', @ContactId)
]%%

<h2>Thank you for submitting the form.</h2><br>
<h3>The amount entered was $ %%=v(@finalAmount)=%%</h3>
<br><br>
 @amount: %%=v(@amount)=%% <br>
 @freeAmount:%%=v(@freeAmount)=%% <br>
 @finalAmount: %%=v(@finalAmount)=%% <br>
 @opportunity: %%=v(@opportunity)=%% <br>
<br>
CreateSalesforceObject('Opportunity', 6, 'Name', %%=v(@name)=%%, 'Amount', %%=v(@finalAmount)=%%, 'RecordTypeId', '0126C000000H9uvQAC', 'CloseDate', %%=v(@date)=%%, 'StageName', 'Received','npsp__Primary_Contact__c', %%=v(@ContactId)=%%)

%%[ ELSE ]%%

<table style="padding: 20px;"><tr><td>
      <h2>Please fill in the form:</h2>
      <form action="%%=RequestParameter('PAGEURL')=%%" method="post">
         <label>First name: </label><input type="text" name="firstname" required=""><br>
         <label>Last name: </label><input type="text" name="lastname" required=""><br>
         <label>Email: </label><input type="text" name="email" required=""><br><br>
         <input type="radio" name="Amount" value="1000" required=""> $ 1000<br>
         <input type="radio" name="Amount" value="500"> $ 500<br>
         <input type="radio" name="Amount" value="250"> $ 250<br>
         <input type="radio" name="Amount" value="100"> $ 100<br>
         <input type="radio" name="Amount" value="50"> $ 50<br>         
         <input type="radio" name="Amount" value=""> $ <input type="number" name="freeAmount" value=""><br>
         <input name="submitted" type="hidden" value="true"><br>
         <input type="submit" value="Submit">
      </form>  
</td></tr></table>

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

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.