Overview

The document provides examples of common errors to avoid when writing JavaScript for Intacct pages.


Error: Unterminated regular expression literal

Consider the following formula:

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:

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:

var fd = (parseInt("{!myRecords.follow_up_date#ms!}") / (1000*60*60*24));

Error: Missing ) after condition

Consider the following formula:

if({!creditpayinfo.response!} == ""){
    . . .

The formula is expanded as follows:

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:

if("{!creditpayinfo.response!}" == "")

Error: Invalid assignment left-hand side

Consider the following formula:

var closedDate = "{!myRecords.closed_date!}";

if(({!myRecords.amount_owed!} < 0.01) && "{!myRecords.closed_date!}" = ""){
    . . .

The formula is expanded as follows:

function wrapper() {
var closedDate = "";

if((413.73 < 0.01) && "" = ""){
    . . .

Remember to use the equality operator (==) and not the assignment (=) operator.

"{!myRecords.closed_date!}" == "" ...

Error: Invalid increment operand

Consider the following formula:

"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:

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:

<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:

{ 
    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.

{!REC1207.monthly_payment#value!}*12

Error: Missing ; before statement

Consider the following formula:

"Check Date: " + {!lock_exception.check_date!} + ... 

The formula is expanded as follows:

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.

"{!lock_exception.check_date!}"

Error: Missing ; before statement

Consider the following formula:

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:

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