SCIS Event Validators

SuiteCommerce InStore (SCIS) enables administrators to customize the application to meet specific business and design needs. The validator.js file contains code snippets that can run before or after a specific backend event occurs in the shopping cart. The pre-validation code defines what is returned. For example, either the event is not run (and an error message appears in the SCIS UI), or there is success ("1” is returned) and the event runs as expected.

Note:

Using event validators is the recommended way to customize the application for specific business workflows and design needs. Client scripts are not supported for this purpose. Client scripts are only supported with AvaTax integrations.

This section includes reference information about how to modify the validator.js file and available methods, supported backend events, and a list of objects and their properties. Read the following topics for more information:

How to Modify the validator.js File

The validators.js file is installed by the SuiteApp. By default, the JavaScript is commented, but administrators or web developers can remove the comments in the code to use the default values or make changes to the file.

To modify the validator.js file:

  1. Go to Web Site Hosting Files > Live Hosting Files > SSP Applications > NetSuite Inc. - POS > SuiteCommerce InStore.

  2. Click Edit next to validators.js.

  3. Remove the comment around the code snippet to use the default values included in the file. You can also edit the code to customize your implementation of SCIS.

  4. Click Save.

Setting a Variable in Session

You can use a validator to implement a particular workflow that is important to your business. For example, you can add a popup message when some value is missing from an order. To accomplish this with one of the supported event validators, you must set a variable in the user session.

Note the following example:

          var context = nlapiGetContext();
context.setSessionObject('mykey', 'my value');

// then

var theValue = context.getSessionObject('mykey'); 

        

Methods

The following methods are available:

addLine(data)

This has a callback function with an argument of type line. Note the following example:

          //EVENTS
var data = {"line": {"isNew": true,"quantity":1, "line": 1, "item":{"internalid":108}}};
SCISCartComponent.addLine(data).then(function(line) {
    console.log('The line added was: ' + JSON.stringify(line));   
}); 

        

updateLine(data)

updateLine(data)

          var data = {"item":{"internalid":108},"quantity":2, "line": 1};
SCISCartComponent.updateLine(data).then(function(line) {
    console.log('The line updated was: ' + JSON.stringify(line));   
}); 

        

getLines()

This has a callback function with an array argument, this contains objects of type line. Note the following example:

          SCISCartComponent.getLines()
.then(function(lines)
{ 
    var countLines = lines.length;
    if (countLines >= 10)
    {
        throw new Error('You have added ' +  countLines + ' items. You should add only until ten items');
    }
}); 

        

getSummary()

This has a callback function and returns an object of type summary, note the following example:

          SCISCartComponent.getSummary()
.then(function(summary)
{ 
    if (summary.total > 10000) {
        throw new Error('You can not make sales with a total greater than 10000');
    }
}); 

        

Events

You can customize certain events that occur in the shopping cart.

object.on('event', callback, [context])

The following events in SCIS support customization:

beforeAddLine

The callback gets one argument (Line), for example:

          //EVENTS
SCISCartComponent.on('beforeAddLine', function(line) {
    console.log('EVENTO BeforeAddLine ', JSON.stringify(line));
}); 

        

afterAddLine

The callback gets one argument (Line), for example:

          //EVENTS
SCISCartComponent.on('afterAddLine', function(line) {
    console.log('EVENT AfterAddLine ', JSON.stringify(line));
}); 

        

beforeVoidLine

The callback gets one argument (Line), for example:

          //EVENTS
SCISCartComponent.on('beforeVoidLine', function(line) {
    console.log('EVENT BEFORE VOID LINE', ' line is void: ' + line.voidLine);
}); 

        

afterVoidLine

The callback gets one argument (Line), for example:

          //EVENTS
SCISCartComponent.on('afterVoidLine', function(line) {
    console.log('EVENT AfterVoidLine', ' line is void: ' + line.voidLine);
}); 

        

beforeUpdateLine

The callback gets one argument (Line), for example:

          //EVENTS
SCISCartComponent.on('beforeUpdateLine', function(line) {
    'use strict';
    console.log('EVENT BeforeUpdateLine', JSON.stringify(line));
    var quantity = line.quantity;
    if (quantity > 10) {
        throw new Error('You can not update lines with quantity greater than 10.');
    }
}); 

        

afterUpdateLine

The callback gets one argument (Line), for example:

          //EVENTS
SCISCartComponent.on('afterUpdateLine', function(line) {
    console.log('EVENT AfterUpdateLine', ' line updated: ' + JSON.stringify(line));
}); 

        

beforeSetCustomer

The callback gets one argument (Customer). Customer is an ID for example:

          //EVENTS
SCISCartComponent.on('beforeSetCustomer', function(customer) {
    'use strict';
    console.log('EVENT BeforeSetCustomer' + JSON.stringify(customer));
    var customerId = 0;
    if (customer == customerId) {
        throw new Error('The customer with the id ' + customerId + ' can not be used.');
    }
}); 

        

afterSetCustomer

The callback gets one argument (Customer). Customer is an ID for example:

          //EVENTS
SCISCartComponent.on('afterSetCustomer', function(customer) {
    console.log('EVENT AfterSetCustomer' + JSON.stringify(customer));
}); 

        

beforeReturnLine

The callback gets one argument (Line), for example:

          //EVENTS
SCISCartComponent.on('beforeReturnLine', function(line) {
    'use strict';
    console.log('EVENT BeforeReturnLine', JSON.stringify(line));
    var quantity = line.quantity;
    if (quantity > 2) {
        throw new Error('You can not return lines with quantity greater than 2.');
    }
}); 

        

afterReturnLine

Note the following example:

          //EVENTS
SCISCartComponent.on('afterReturnLine', function(line) {
    console.log('EVENT AfterReturnLin', JSON.stringify(line));
}); 

        

beforeAddDiscount

The callback gets one argument (Discount), for example:

          //EVENTS
SCISCartComponent.on('beforeAddDiscount', function(discount) {
    'use strict';
    console.log('EVENT BeforeAddDiscount', JSON.stringify(discount));
     
    var discountValue = discount.baseprice
    ,   isPercentage = discountValue.indexOf('%') > 0
    ,   discountRate = discountValue.replace('%', '').replace('-', '');
 
    if (discountValue && isPercentage && discountRate > 50) {
        throw new Error('You can not apply discounts greater than 50%.');
    }
}); 

        

afterAddDiscount

The callback gets one argument (Discount), for example:

          //EVENTS
SCISCartComponent.on('afterAddDiscount', function(discount) {
    'use strict';
    console.log('EVENT AfterAddDiscount', JSON.stringify(discount));
}); 

        

beforeAddGiftItem

The callback gets one argument (gift), for example:

          //EVENTS
SCISCartComponent.on('beforeAddGiftItem', function(gift) {
    'use strict';
    console.log('EVENT BeforeAddGiftItem', JSON.stringify(gift));
 
    var giftValue = gift.baseprice
    ,   maxValue = 400;
 
    if (giftValue > maxValue) {
        throw new Error('You can not add a gift card with amount greater than ' + maxValue + ' .');
    }
});; 

        

afterAddGiftItem

The callback gets one argument (gift), for example:

          //EVENTS
SCISCartComponent.on('afterAddGiftItem', function(gift) {
    'use strict';
    console.log('EVENT AfterAddGiftItem', JSON.stringify(gift));
});; 

        

beforeAddGlobalDiscount

The callback gets one argument (Discount), for example:

          //EVENTS
SCISCartComponent.on('beforeAddGlobalDiscount', function(discount) {
    'use strict';
    console.log('EVENT BeforeAddGlobalDiscount', JSON.stringify(discount));
 
    var discountValue = discount.rate
    ,   isPercentage = discountValue.indexOf('%') > 0
    ,   discountRate = discountValue.replace('%', '').replace('-', '');
 
    if (isPercentage && discountRate > 20) {
        throw new Error('You can not apply discounts greater than 20%.');
    }
}); 

        

afterAddGlobalDiscount

The callback gets one argument (Discount), for example:

          //EVENTS
SCISCartComponent.on('afterAddGlobalDiscount', function(discount) {
    'use strict';
    console.log('EVENT AfterAddGlobalDiscount ', JSON.stringify(discount));
}); 

        

beforeCancelTransaction

The callback gets one argument (Transaction), for example:

          //EVENTS
 
SCISCartComponent.on('beforeCancelTransaction', function(transaction) {
    'use strict';
    console.log('EVENT BeforeCancelTransaction ', JSON.stringify(transaction));
}); 

        

afterCancelTransaction

The callback gets one argument (Transaction), for example:

          //EVENTS
 
SCISCartComponent.on('afterCancelTransaction', function(transaction) {
    'use strict';
    console.log('EVENT AfterCancelTransaction ', JSON.stringify(transaction));
}); 

        

beforePay

The callback gets one argument (params). The argument (params) is an object with two attributes. The attribute '0' contains the order and the attribute '1' contains an array of payment objects. Note the following example:

          //EVENTS
 
SCISCartComponent.on('beforePay', function(params) {
    'use strict';
    console.log('EVENT BeforePay ', JSON.stringify(params));
    var order = params[0]
    ,   payments = params[1];
    if (order && payments)
    {
       var countPayments = payments.length
       ,   lastPayment = countPayments > 0 ? payments[countPayments - 1] : undefined
       ,   maxPaymentAllowed = 1000;
 
       if (lastPayment && lastPayment.paymentmethodname !== 'Cash' && order.total > maxPaymentAllowed)
       {
            throw new Error('You can not apply a payment with a total greater than ' + maxPaymentAllowed + '. It is only allowed to cash payments.');
       }
    }
}); 

        

afterPay

The callback gets one argument (params). The argument (params) is an object with two attributes. The attribute '0' contains the order and the attribute '1' contains an array of payment objects. Note the following example:

          //EVENTS
 
SCISCartComponent.on('afterPay', function(params) {
    'use strict';
    console.log('EVENT AfterPay ', JSON.stringify(params));
}); 

        

Arguments

The following arguments are accessible:

Line

This argument contains the following properties in SCIS:

Note the following example:

          {
      "line":1,
      "item": {"internalid": 108},
      "isdonationitem":false,
      "quantity":"1.0",
      "voidLine":true,
      "order":"F",
      "description":"",
      "giftcertfrom":"Mrs. Wolfe",
      "giftcertmessage":"You received a gift from MySCISWebsite",
      "giftcertnumber":"1234560",
      "giftcertrecipientemail":"email address",
      "giftcertrecipientname":"Mr. Wolfe",
      "tax_code":"116",
      "note":"",
      "excludefromraterequest":"F",
      "custcol_ns_pos_voidqty":""
} 

        

Payment

This argument contains the following properties in SCIS:

Note the following example:

          {
      "paymentmethod": "1",
      "paymentmethodname": "Cash",
      "payment": 1300,
      "total": 1300,
      "rounding": true
} 

        

Discount

This argument contains rate as the only property in SCIS. Note the following example:

          {

"rate": "-20%"
} 

        

Customer

This argument contains id as the only property in SCIS. Note the following example:

          114 

        

Transaction

This argument contains id as the only property in SCIS. Note the following example:

          2123 

        

Summary

This argument contains the following properties in SCIS:

Note the following example:

          {
    "amountdue": -7.38,
    "changedue": 7.38,
    "couponcode": "",
    "createddate": "2017-08-03T16:08:00.000Z",
    "createdfrom": ""
    "discounttotal": "0.00",
    "giftcertapplied": "0.00"
    "handlingcost": "0.00",
    "shippingcost": "",
    "shippingcostoverridden": "F",
    "shippingtax1rate": "",
    "subtotal": "1042.62",
    "tax2total": null,
    "taxtotal": "0.00",
    "total": "1042.62",
    "tranid": "CS1659",
} 

        

Related Topics

Customizing the Configuration File
Editing the CustomConfiguration.js File
Modifying Included Saved Searches

General Notices