Use Scriptable Cart Messaging to offer promotional messages when item is added to cart. This is useful for the user who had implemented Scriptable Cart. It helps them to shows what’s happening in the script.
Users can use SuiteScript to display custom messages when the shopping cart contains an item they identify as the trigger item.
Once certain item is added, the script will run and it will populate the custom body field with the value from the script. In the Web Site theme customization, user can add a tag that will pull the value from that custom field. Then, display a pop up message.
Below are some sample codes:-
Sample code :- SuiteScript 1.0
<pre><code class="language-suitescript">var printerIDs = { 501:"", 502:"", 503:"" };
//Note that this client event function must return a value of true or false
//This function will triger when item is added to the cart
function customValidateLine(type)
{
var itemID = nlapiGetCurrentLineItemValue ('item', 'item');
//Create an if condition using itemId to display and offer promotional messages
//If specific item is added to the cart, it will display the custom message
//In the Example below, the 'custbody_popupmsg' is internal ID of Transaction Body Field
if (itemID == '5')
{
nlapiSetFieldValue('custbody_popupmsg', 'Please note that our monitors only come with a 30 day warranty');
return true;
}
// Note: For matrix item, Users can set custom message for each child item
else if (itemID == '178')
{
nlapiSetFieldValue('custbody_popupmsg', 'You have chosen red which has 50% discount');
return true;
}
else if (itemID == '179')
{
nlapiSetFieldValue('custbody_popupmsg', 'You have chosen white which has 20% discount');
return true;
}
// Users can also set group of items using an array
// In this example, printerIDs contains the items (internal ID) 501, 502 and 503
else if (itemID in printerIDs)
{
nlapiSetFieldValue('custbody_popupmsg', 'Please note that our printers have 20 percent discount');
return true;
}
else
{
nlapiSetFieldValue('custbody_popupmsg', 'We offer up to 50% discount on selected items');
return true;
}
return true;
}</code></pre>
Sample code :– SuiteScript 2.0
<pre><code class="language-suitescript">var printerIDs = { 501: "", 502: "", 503: ""};
function validateLine(scriptContext) {
var currRecord = scriptContext.currentRecord
var itemID = currRecord.getCurrentSublistValue({ sublistId: 'item', fieldId: 'item' })
if (itemID == '5') { currRecord.setValue({ fieldId: 'custbody_popupmsg', value: 'Please note that our monitors only come with a 30 day warranty' })
return true; } else if (itemID == '178') { currRecord.setValue({ fieldId: 'custbody_popupmsg', value: 'You have chosen red which has 50% discount' })
return true; } else if (itemID == '179') { currRecord.setValue({ fieldId: 'custbody_popupmsg', value: 'You have chosen white which has 20% discount' })
return true; } else if (itemID in printerIDs) { currRecord.setValue({ fieldId: 'custbody_popupmsg', value: 'Please note that our printers have 20 percent discount' })
return true; } else(itemID in printerIDs) { currRecord.setValue({ fieldId: 'custbody_popupmsg', value: 'We offer up to 50% discount on selected items' })
return true; }
return true;
}</code></pre>