Buckets:
| title: Common JavaScript Errors | Sage Intacct Developer | |
| url: https://developer.intacct.com/platform-services/javascript-errors/ | |
| # Common JavaScript Errors | Sage Intacct Developer | |
| Overview | |
| AJAX Gateway | |
| AJAX SDK for JavaScript | |
| Page Script Walkthrough | |
| Application Tutorial | |
| Other Script Examples | |
| Common JavaScript Errors | |
| Trigger Examples | |
| * Overview | |
| * Error: Unterminated regular expression literal | |
| * Error: Missing ) after condition | |
| * Error: Invalid assignment left-hand side | |
| * Error: Invalid increment operand | |
| * Error: Invalid return | |
| * Error: Missing ; before statement | |
| * Error: Missing ; before statement | |
| --- | |
| ## Overview | |
| The document provides examples of common errors to avoid when writing JavaScript for Sage Intacct pages. | |
| --- | |
| ## Error: Unterminated regular expression literal | |
| Consider the following formula: | |
| ```xml | |
| if ("{!CollTmptoPerm.name#text!}" == "SOME-TEXT"){ | |
| var f = "{!myRecords.follow_up_date#userformat!}"; | |
| var i = "{!myRecords.process_date#userformat!}"; | |
| if (f == i) return true; | |
| var fd = ({!myRecords.follow_up_date#ms!} / (1000*60*60*24)); | |
| . . . | |
| ``` | |
| If `follow_up_date` is a null date field, the formula is expanded as follows: | |
| ```xml | |
| function wrapper() { | |
| if ("Active" == "SOME-TEXT"){ | |
| var f = ""; | |
| var i = "10.05.2016"; | |
| if (f == i) return true; | |
| var fd = ( / (1000*60*60*24)); | |
| . . . | |
| ``` | |
| Because a null date field expands to an empty string when the `#ms` suffix is used, `parseInt` must be used so that null fields are handled correctly: | |
| ```xml | |
| var fd = (parseInt("{!myRecords.follow_up_date#ms!}") / (1000*60*60*24)); | |
| ``` | |
| ## Error: Missing ) after condition | |
| Consider the following formula: | |
| ```xml | |
| if({!creditpayinfo.response!} == ""){ | |
| . . . | |
| ``` | |
| The formula is expanded as follows: | |
| ```xml | |
| function wrapper() { | |
| if(Status updated successfully check with cardID: 187579,amt: 2058.24 == ""){ | |
| . . . | |
| ``` | |
| Because fields expand without any special delimiters, you must add double quotes for string comparisons: | |
| ```xml | |
| if("{!creditpayinfo.response!}" == "") | |
| ``` | |
| ## Error: Invalid assignment left-hand side | |
| Consider the following formula: | |
| ```xml | |
| var closedDate = "{!myRecords.closed_date!}"; | |
| if(({!myRecords.amount_owed!} < 0.01) && "{!myRecords.closed_date!}" = ""){ | |
| . . . | |
| ``` | |
| The formula is expanded as follows: | |
| ```xml | |
| function wrapper() { | |
| var closedDate = ""; | |
| if((413.73 < 0.01) && "" = ""){ | |
| . . . | |
| ``` | |
| Remember to use the equality operator (==) and not the assignment (=) operator. | |
| ```xml | |
| "{!myRecords.closed_date!}" == "" ... | |
| ``` | |
| ## Error: Invalid increment operand | |
| Consider the following formula: | |
| ```xml | |
| "Check Date: "+{!lock_exception.check_date!}+"Batch:"+{!lock_exception.batch_number!}+" Item:"+{!lock_exception.item_number!}+" Check #:"+{!lock_exception.check_number!}+" Acct:"+{!lock_exception.acct_number!}; | |
| ``` | |
| The formula is expanded as follows: | |
| ```xml | |
| function wrapper() { | |
| return "Check Date: "+08-10-16+"Batch:"++" Item:"++" Check #:"+67291+" Acct:"+; | |
| } | |
| wrapper(); | |
| ``` | |
| As mentioned previously, use `parseInt` when expanding possibly null fields. | |
| ## Error: Invalid return | |
| Consider the following formula: | |
| ```xml | |
| <TR> | |
| <TD><b>{!REC1207.RVENDOR!}</b></TD> | |
| <TD>{!REC1207.leased#value!}</TD> | |
| <TD>{!REC1207.start_date#userformat!}</TD> | |
| <TD>{!REC1207.end_date#userformat!}</TD> | |
| <TD>{!REC1207.monthly_payment!}</TD> | |
| <TD>#EVAL[{ | |
| var inc = '{!REC1207.start_date#userformat!}'; | |
| var yearinc = inc.substr(6,4); | |
| if (yearinc >= '2012') { | |
| return {!REC1207.monthly_payment!}*12 | |
| } | |
| } | |
| ]</TD> | |
| </TR> | |
| ``` | |
| The formula is expanded as follows: | |
| ```xml | |
| { | |
| var inc = '11/29/2012'; | |
| var yearinc = inc.substr(6,4); | |
| if (yearinc >= '2012') { | |
| return $6,464.33*12 | |
| } | |
| } | |
| ``` | |
| The currency field expands with full punctuation, so the `#value` suffix is needed in the formula. | |
| ```xml | |
| {!REC1207.monthly_payment#value!}*12 | |
| ``` | |
| ## Error: Missing ; before statement | |
| Consider the following formula: | |
| ```xml | |
| "Check Date: " + {!lock_exception.check_date!} + ... | |
| ``` | |
| The formula is expanded as follows: | |
| ```xml | |
| function wrapper() { | |
| return "Check Date: "+9\u002f16\u002f2016+" | |
| wrapper(); | |
| ``` | |
| The date field expands into a string literal with Unicode escapes for slashes unless it is double quoted in the formula. | |
| ```xml | |
| "{!lock_exception.check_date!}" | |
| ``` | |
| ## Error: Missing ; before statement | |
| Consider the following formula: | |
| ```xml | |
| var returnVal = "0.00"; | |
| returnVal = {!advance.total_paid_from_initial_advance!} - {!advance.total_reconcilled!} - {!advance.total_deducted_from_payroll!} - {!advance.total_payment_received_from_employee!} + {!advance.total_reimbursed_to_employee!}; | |
| if(returnVal == "" || returnVal == 0){ | |
| returnVal = "$0.00"; | |
| } | |
| return returnVal; | |
| ``` | |
| The formula is expanded as follows: | |
| ```xml | |
| function wrapper() { | |
| var returnVal = "0.00"; | |
| returnVal = 0 - 1343 - 0 - 0 + ERROR: Syntax error in formula SOURCE: Formula field Travel Advance.Total Reimbursements Paid; | |
| if(returnVal == "" || returnVal == 0){ | |
| returnVal = "$0.00"; | |
| } | |
| return returnVal; | |
| } | |
| wrapper(); | |
| ``` | |
| Here, one part of the application detects and reports the syntax error in {!advance.total\_reimbursed\_to\_employee!}, but another part of the application uses the error as the value of the field’s expansion. | |
| Provide feedback | |
Xet Storage Details
- Size:
- 5.27 kB
- Xet hash:
- f5f5310ecfdb4e3c52286ecb6fb688844b102a2cc86ace2f925ab40937b73042
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.