NetSuite CPQ Ecommerce Integration
Install NetSuite CPQ Configurator to use NetSuite CPQ Ecommerce Integration. For more information, see Installing NetSuite CPQ SuiteApps.
With NetSuite CPQ Ecommerce Integration, you can convert standard line items into configured line items and update transactions in the background using NetSuite CPQ Configurator products. For example, you can process transactions that include line items added from SuiteCommerce web stores or other ecommerce platforms. You can use line items or information from custom line fields as materials, create a configuration with those materials, delete the existing line items on the transaction, and add the configured line item.
The transaction processing is handled by the CPQE-SC-BCL script (customscript_cpqe_sc_bcl), which is the scheduled script for NetSuite CPQ Ecommerce Integration. To convert line items into a configured line item, create a server-side script that launches the CPQE-SC-BCL scheduled script and a NetSuite CPQ Configurator product.
The most common use case involves launching the scheduled script from a user event script, which runs when users save or edit a transaction. The user event script includes a custom condition and the NetSuite CPQ Configurator product ID. The custom condition determines whether the scheduled script should be launched for a specific transaction.
The processing flow for NetSuite CPQ Ecommerce Integration runs one time while going through all the following four phases:
-
Runs before-event actions according to their sequence number.
Note:The event is the refresh of the building blocks.
-
Refreshes building blocks according to their sequence number.
-
Runs after-event action according to their sequence number.
-
Submits the configuration to the transaction record.
This phase includes creating the configuration record and adding the configured items to the transaction record. Then, it saves the transaction.
Although NetSuite CPQ Ecommerce Integration uses NetSuite CPQ Configurator products, some features aren't supported. The following capabilities aren't available in NetSuite Ecommerce Integration:
-
Using item creation records and creation records.
-
Setting transaction fields based on configuration data using mapping records.
-
Searching tables with SuiteQL.
-
Sourcing prices from materials.
-
Showing additional item prices in the Summary.
To convert line items into a configured line item:
-
Create a NetSuite CPQ Configurator product.
-
Create all required building blocks, such as materials and routing steps.
-
In the product, create actions that include the tasks to generate a configuration from the line items on the transaction.
Note:Write your actions' code using JavaScript ES5. NetSuite CPQ Ecommerce Integration doesn't support JavaScript ES6 for actions.
Unlike NetSuite CPQ Configurator, NetSuite CPQ Ecommerce integration doesn't distinguish between client-side and server-side actions. All actions in NetSuite CPQ Ecommerce Integration run on the server. Don't use native JavaScript code that interacts with the browser window and the DOM.
If you want to use the same product in both NetSuite CPQ Configurator and NetSuite CPQ Ecommerce Integration, create separate actions for native JavaScript client-side code and add
X(SOLE/BC)as a rule. -
In the Rule field of the actions, enter the
SOLE/BCpredefined answer. With this predefined answer, the action will run only if the product is launched by NetSuite CPQ Ecommerce Integration. -
Use the debugging tool to verify that your product is set up correctly. For more information, see Testing and Debugging the Conversion into Configured Items.
-
-
Write the script to launch NetSuite CPQ Ecommerce Integration.
-
In SuiteScript 2.x, use one of the following server-side script types to launch the CPQE-SC-BCL scheduled script:
-
Suitelet
-
RESTlet
-
User-event
-
Scheduled
-
-
In the server-side script, pass the following parameters to the CPQE-SC-BCL script:
-
custscript_cpqe_scf_productid- Internal product ID.Note:To view the internal product ID, go to CPQ > Configurator > Product Maintenance. In the product list, find the product ID and view the value under the Internal ID column.
-
custscript_cpqe_scf_rectype- Transaction type. -
custscript_cpqe_scf_oid- Transaction ID. -
custscript_cpqe_scf_nosub(no submit) - Defines whether the transaction will be updated (trueorfalse). It's false by default, so the transaction will be updated if you omit the parameter.
See the following example:
define(['N/task'], (_nTask) => { // [...] _nTask.create({ taskType: _nTask.TaskType.SCHEDULED_SCRIPT, scriptId: 'customscript_cpqe_sc_bcl', params: { custscript_cpqe_scf_productid: '13', custscript_cpqe_scf_rectype: 'salesorder', custscript_cpqe_scf_oid: '1086', custscript_cpqe_scf_nosub: false } }); // [...] -
-
Add a custom condition to specify when the transaction should be processed. For example, the transaction is only processed if a certain field has a specific value.
Note:To prevent the transaction from being processed multiple times when it's edited, make sure you reset the custom condition. You can reset the custom condition either in the server-side script or in actions in the NetSuite CPQ Configurator product.
-
-
Launch the CPQE-SC-BCL script (customscript_cpqe_sc_bcl) from the server-side script. As an example, see Starting the Conversion Process to Configured Item from a User-Event Script.
-
Deploy the server-side script on the transaction. For more information, see Deploying a Script by using the Deployments Sublist.
Starting the Conversion Process to Configured Item from a User-Event Script
This example shows a user event script deployed on the sales order record. The script runs when users or other scripts create or edit a sales order. In this example, the runAfterSubmit function in this example is assigned to the afterSubmit event. Because the script also runs for edited transactions, the custom condition is reset to avoid processing the transaction multiple times.
This example also includes code to handle situations where the request can't be added to the task queue when the scheduled script is launched. The user event script creates the CPQE-BC-Launch-Request custom record, also known as postponed launch record, which stores information about the launch request.
The CPQE-SC-ScanBCLTasks scheduled script runs every 15 minutes to verify whether there are launch request records. Then, this script launches NetSuite CPQ Ecommerce Integration for every created postponed launch record. If the launch is successful, the postponed launch record is removed. If there are too many requests, the script will try again later.
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/log', 'N/runtime', 'N/record', 'N/task'], (_nLog, _nRuntime, _nRecord, _nTask) => {
const runAfterSubmit = (context) => {
const type = context.type;
_nLog.debug({ title: 'UE check', details: type });
// Runs when creating or updating existing transactions
if (type !== context.UserEventType.CREATE && type !== context.UserEventType.EDIT) {
return;
}
const rec = context.newRecord;
const recType = rec.type;
const recId = rec.id;
const productId = 18; // NetSuite CPQ Configurator product ID
if (checkLaunchCriteria(rec)) {
const data = {
custscript_cpqe_scf_productid: productId,
custscript_cpqe_scf_rectype: recType,
custscript_cpqe_scf_oid: recId,
custscript_cpqe_scf_nosub: false
};
_nLog.debug({ title: 'Now processing order', details: recId });
// Direct launch of the CPQE-SC-BCL scheduled script
const status = directLaunch(data);
if (status === _nTask.TaskStatus.QUEUED) {
resetLaunchCriteria(recType, recId);
} else {
_nLog.debug({ title: 'ERROR', details: 'Direct launch failed' });
// Postponed launch using the launch request record
const id = postponedLaunch(data);
if (id) {
_nLog.debug({ title: 'Postponed launch successful', details: id });
} else {
_nLog.debug({ title: 'ERROR', details: 'Postponed launch failed' });
}
}
}
};
// Verifies the custom condition
function checkLaunchCriteria(rec) {
const memo = rec.getValue({ fieldId: 'memo' });
return memo === 'bc';
}
// Resets the custom condition
function resetLaunchCriteria(recType, recId) {
_nRecord.submitFields({
type: recType,
id: recId,
values: {
memo: ''
}
});
}
// Launch of the scheduled script
function directLaunch(params) {
try {
const scheduledScriptTask = _nTask.create({
taskType: _nTask.TaskType.SCHEDULED_SCRIPT,
scriptId: 'customscript_cpqe_sc_bcl',
params: params
});
const taskId = scheduledScriptTask.submit();
_nLog.debug({ title: 'Direct launch status', details: 'QUEUED: ' + taskId });
return _nTask.TaskStatus.QUEUED;
} catch (e) {
_nLog.error({ title: 'Direct launch error', details: e.message });
return 'FAILED';
}
}
// Postponed launch (create launch request record)
function postponedLaunch(data) {
try {
const r = _nRecord.create({
type: 'customrecord_cpqe_bc_lrequest',
isDynamic: true
});
r.setValue({ fieldId: 'custrecord_cpqe_bc_lrequest_prodid', value: data.custscript_cpqe_scf_productid });
r.setValue({ fieldId: 'custrecord_cpqe_bc_lrequest_rec_type', value: data.custscript_cpqe_scf_rectype });
r.setValue({ fieldId: 'custrecord_cpqe_bc_lrequest_order_id', value: data.custscript_cpqe_scf_oid });
return r.save();
} catch (e) {
_nLog.error({ title: 'Postponed launch error', details: e.message });
return null;
}
}
// Assigns the runAfterSubmit function to the afterSubmit event
return { afterSubmit: runAfterSubmit };
});