ns-suitescript-mocks
Version:
Collection of mocks that can be used to improve unit-tests for SuiteScript 2.0.
1,424 lines (1,317 loc) • 193 kB
JavaScript
const _ = require('lodash');
const moment = require('moment');
const record = require('../Utils/record');
const file = require('../N/file');
const { random } = require('../Utils/utils');
const showLogs = false;
/**
* @projectDescription SuiteScript JavaScript library summary.
*
* Note that there are some restrictions on API usage. Also note that the only 2 objects that can be
* contructed are nlobjSearchFilter and nlobjSearchColumn. All other objects can only be created via
* top-level function or method calls.
*
* The @governance tag refers to the usage governance for an API call
* The @restricted tag refers to any known restrictions with a particular API call
*
* All Object arguments are Javascript Objects used as hash tables for specifying key-value pairs
*
* @since 2005.0 Support scripting of current record in Client SuiteScript
* @version 2007.0 Support scripting of records in user events, portlets, and scheduled scripts
* @version 2008.1 Support scripting of web requests (Suitelets) and user interfaces (UI Object API)
* @version 2009.1 Support scripting of file objects
* @version 2009.2 Support scripting of setup records and assistant (multi-step) pages
* @version 2009.2 converted JS template to use eclipse code completion friendly format
* @version 2010.1 Suppport dynamic scripting
*/
/**
* Return a new record using values from an existing record.
* @governance 10 units for transactions, 2 for custom records, 4 for all other records
*
* @param {string} type The record type name.
* @param {int} id The internal ID for the record.
* @param {Object} initializeValues Contains an array of name/value pairs of defaults to be used during record initialization.
* @return {nlobjRecord} Returns an nlobjRecord object of a copied record.
*
* @since 2007.0
*/
exports.nlapiCopyRecord = function (type, id, initializeValues) { };
/**
* Load an existing record from the system.
* @governance 10 units for transactions, 2 for custom records, 4 for all other records
*
* @param {string} type The record type name.
* @param {int} id The internal ID for the record.
* @param {Object} initializeValues Contains an array of name/value pairs of defaults to be used during record initialization.
* @return {nlobjRecord} Returns an nlobjRecord object of an existing NetSuite record.
*
* @exception {SSS_INVALID_RECORD_TYPE}
* @exception {SSS_TYPE_ARG_REQD}
* @exception {SSS_INVALID_INTERNAL_ID}
* @exception {SSS_ID_ARG_REQD}
*
* @since 2007.0
*/
exports.nlapiLoadRecord = function (type, id, initializeValues) {
initializeValues = initializeValues || {};
initializeValues.id = id;
return new record(type, initializeValues);
};
/**
* Instantiate a new nlobjRecord object containing all the default field data for that record type.
* @governance 10 units for transactions, 2 for custom records, 4 for all other records
*
* @param {string} type record type ID.
* @param {Object} initializeValues Contains an array of name/value pairs of defaults to be used during record initialization.
* @return {nlobjRecord} Returns an nlobjRecord object of a new record from the system.
*
* @exception {SSS_INVALID_RECORD_TYPE}
* @exception {SSS_TYPE_ARG_REQD}
*
* @since 2007.0
*/
exports.nlapiCreateRecord = function (type, initializeValues) { return new record(type, initializeValues); };
/**
* Submit a record to the system for creation or update.
* @governance 20 units for transactions, 4 for custom records, 8 for all other records
*
* @param {nlobjRecord} record nlobjRecord object containing the data record.
* @param {boolean} [doSourcing] If not set, this argument defaults to false.
* @param {boolean} [ignoreMandatoryFields] Disables mandatory field validation for this submit operation.
* @return {string} internal ID for committed record.
*
* @exception {SSS_INVALID_RECORD_OBJ}
* @exception {SSS_RECORD_OBJ_REQD}
* @exception {SSS_INVALID_SOURCE_ARG}
*
* @since 2007.0
*/
exports.nlapiSubmitRecord = function (record, doSourcing, ignoreMandatoryFields) { return record.getId(); };
/**
* Delete a record from the system.
* @governance 20 units for transactions, 4 for custom records, 8 for all other records
*
* @param {string} type The record type name.
* @param {int} id The internal ID for the record.
* @return {void}
*
* @exception {SSS_INVALID_RECORD_TYPE}
* @exception {SSS_TYPE_ARG_REQD}
* @exception {SSS_INVALID_INTERNAL_ID}
* @exception {SSS_ID_ARG_REQD}
*
* @since 2007.0
*/
exports.nlapiDeleteRecord = function (type, id) { return id; };
/**
* Perform a record search using an existing search or filters and columns.
* @governance 10 units
* @restriction returns the first 1000 rows in the search
*
* @param {string} type record type ID.
* @param {int, string} [id] The internal ID or script ID for the saved search to use for search.
* @param {nlobjSearchFilter, nlobjSearchFilter[]} [filters] [optional] A single nlobjSearchFilter object - or - an array of nlobjSearchFilter objects.
* @param {nlobjSearchColumn, nlobjSearchColumn[]} [columns] [optional] A single nlobjSearchColumn object - or - an array of nlobjSearchColumn objects.
* @return {nlobjSearchResult[]} Returns an array of nlobjSearchResult objects corresponding to the searched records.
*
* @exception {SSS_INVALID_RECORD_TYPE}
* @exception {SSS_TYPE_ARG_REQD}
* @exception {SSS_INVALID_SRCH_ID}
* @exception {SSS_INVALID_SRCH_FILTER}
* @exception {SSS_INVALID_SRCH_FILTER_JOIN}
* @exception {SSS_INVALID_SRCH_OPERATOR}
* @exception {SSS_INVALID_SRCH_COL_NAME}
* @exception {SSS_INVALID_SRCH_COL_JOIN}
*
* @since 2007.0
*/
exports.nlapiSearchRecord = function (type, id, filters, columns) {
return [record(type, (columns && Array.isArray(columns) ? columns : []).reduce((reducer, column) => {
reducer[column.name] = column.name;
return reducer;
}, {}))];
};
/**
* Perform a global record search across the system.
* @governance 10 units
* @restriction returns the first 1000 rows in the search
*
* @param {string} keywords Global search keywords string or expression.
* @return {nlobjSearchResult[]} Returns an Array of nlobjSearchResult objects containing the following four columns: name, type (as shown in the UI), info1, and info2.
*
* @since 2008.1
*/
exports.nlapiSearchGlobal = function (keywords) { };
/**
* Perform a duplicate record search using Duplicate Detection criteria.
* @governance 10 units
* @restriction returns the first 1000 rows in the search
*
* @param {string} type The recordType you are checking duplicates for (for example, customer|lead|prospect|partner|vendor|contact).
* @param {string[]} [fields] array of field names used to detect duplicate (for example, companyname|email|name|phone|address1|city|state|zipcode).
* @param {int} [id] internal ID of existing record. Depending on the use case, id may or may not be a required argument.
* @return {nlobjSearchResult[]} Returns an Array of nlobjSearchResult objects corresponding to the duplicate records.
*
* @since 2008.1
*/
exports.nlapiSearchDuplicate = function (type, fields, id) { };
/**
* Create a new record using values from an existing record of a different type.
* @governance 10 units for transactions, 2 for custom records, 4 for all other records
*
* @param {string} type The record type name.
* @param {int} id The internal ID for the record.
* @param {string} transformType The recordType you are transforming the existing record into.
* @param {Object} [transformValues] An object containing transform default option/value pairs used to pre-configure transformed record
* @return {nlobjRecord}
*
* @exception {SSS_INVALID_URL_CATEGORY}
* @exception {SSS_CATEGORY_ARG_REQD}
* @exception {SSS_INVALID_TASK_ID}
* @exception {SSS_TASK_ID_REQD}
* @exception {SSS_INVALID_INTERNAL_ID}
* @exception {SSS_INVALID_EDITMODE_ARG}
*
* @since 2007.0
*/
exports.nlapiTransformRecord = function (type, id, transformType, transformValues) { };
/**
* void a transaction based on type and id .
* @governance 10 units for transactions
*
* @param {string} type The transaction type name.
* @param {string} id The internal ID for the record.
* @return {string} if accounting preference is reversing journal, then it is new journal id,
* otherwise, it is the input record id
*
* @since 2014.1
*/
exports.nlapiVoidTransaction = function (type, id) { };
/**
* Fetch the value of one or more fields on a record. This API uses search to look up the fields and is much
* faster than loading the record in order to get the field.
* @governance 10 units for transactions, 2 for custom records, 4 for all other records
*
* @param {string} type The record type name.
* @param {int} id The internal ID for the record.
* @param {string, string[]} fields - field or fields to look up.
* @param {boolean} [text] If set then the display value is returned instead for select fields.
* @return {string, Object} single value or an Object of field name/value pairs depending on the fields argument.
*
* @since 2008.1
*/
exports.nlapiLookupField = function (type, id, fields, text) {
let result = '';
result += type || '';
result += id || 0;
result += fields || '';
result += text || '';
result += random(1, 1000);
return result;
};
/**
* Submit the values of a field or set of fields for an existing record.
* @governance 10 units for transactions, 2 for custom records, 4 for all other records
* @restriction only supported for records and fields where DLE (Direct List Editing) is supported
*
* @param {string} type The record type name.
* @param {int} id The internal ID for the record.
* @param {string, string[]} fields field or fields being updated.
* @param {string, string[]} values field value or field values used for updating.
* @param {boolean} [doSourcing] If not set, this argument defaults to false and field sourcing does not occur.
* @return {void}
*
* @since 2008.1
*/
exports.nlapiSubmitField = function (type, id, fields, values, doSourcing) {
return new record(type, { id, fields, values });
};
/**
* Attach a single record to another with optional properties.
* @governance 10 units
*
* @param {string} type1 The record type name being attached
* @param {int} id1 The internal ID for the record being attached
* @param {string} type2 The record type name being attached to
* @param {int} id2 The internal ID for the record being attached to
* @param {Object} [properties] Object containing name/value pairs used to configure attach operation
* @return {void}
*
* @since 2008.2
*/
exports.nlapiAttachRecord = function (type1, id1, type2, id2, properties) { };
/**
* Detach a single record from another with optional properties.
* @governance 10 units
*
* @param {string} type1 The record type name being attached
* @param {int} id1 The internal ID for the record being attached
* @param {string} type2 The record type name being attached to
* @param {int} id2 The internal ID for the record being attached to
* @param {Object} [properties] Object containing name/value pairs used to configure detach operation
* @return {void}
*
* @since 2008.2
*/
exports.nlapiDetachRecord = function (type1, id1, type2, id2, properties) { };
/**
* Resolve a URL to a resource or object in the system.
*
* @param {string} type type specifier for URL: suitelet|tasklink|record|mediaitem
* @param {string} subtype subtype specifier for URL (corresponding to type): scriptid|taskid|recordtype|mediaid
* @param {string} [id] internal ID specifier (sub-subtype corresponding to type): deploymentid|n/a|recordid|n/a
* @param {string} [pagemode] string specifier used to configure page (suitelet: external|internal, tasklink|record: edit|view)
* @return {string}
*
* @since 2007.0
*/
exports.nlapiResolveURL = function (type, subtype, id, pagemode) { return 'https://system.eu2.netsuite.com/app/site/hosting/scriptlet.nl?script=1&deploy=1'; };
/**
* Redirect the user to a page. Only valid in the UI on Suitelets and User Events. In Client scripts this will initialize the redirect URL used upon submit.
*
* @param {string} type type specifier for URL: suitelet|tasklink|record|mediaitem
* @param {string} subtype subtype specifier for URL (corresponding to type): scriptid|taskid|recordtype|mediaid
* @param {string} [id] internal ID specifier (sub-subtype corresponding to type): deploymentid|n/a|recordid|n/a
* @param {string} [pagemode] string specifier used to configure page (suitelet: external|internal, tasklink|record: edit|view)
* @param {Object} [parameters] Object used to specify additional URL parameters as name/value pairs
* @return {void}
*
* @since 2007.0
*/
exports.nlapiSetRedirectURL = function (type, subtype, id, pagemode, parameters) { };
/**
* Request a URL to an external or internal resource.
* @restriction NetSuite maintains a white list of CAs that are allowed for https requests. Please see the online documentation for the complete list.
* @governance 10 units
*
* @param {string} url A fully qualified URL to an HTTP(s) resource
* @param {string, Object} [postdata] - string, document, or Object containing POST payload
* @param {Object} [headers] - Object containing request headers.
* @param {function} [callback] - available on the Client to support asynchronous requests. function is passed an nlobjServerResponse with the results.
* @return {nlobjServerResponse}
*
* @exception {SSS_UNKNOWN_HOST}
* @exception {SSS_INVALID_HOST_CERT}
* @exception {SSS_REQUEST_TIME_EXCEEDED}
* @exception {SSS_CONNECTION_CLOSED}
* @exception {SSS_CONNECTION_TIME_OUT}
* @exception {SSS_INVALID_URL}
* @exception {SSS_UNSUPPORTED_ENCODING}
*
* @since 2007.0
*/
exports.nlapiRequestURL = function (url, postdata, headers, callback, method) { };
/**
* Allows you to send credentials outside of NetSuite. This API securely accesses a handle to credentials that users specify in a NetSuite credential field.
* @restriction NetSuite maintains a white list of CAs that are allowed for https requests. Please see the online documentation for the complete list.
* @governance 10 units
*
* @param {array} credentials List of credential handles
* @param {string} url A fully qualified URL to an HTTP(s) resource
* @param {string, Object} [postdata] - string, document, or Object containing POST payload
* @param {Object} [headers] - Object containing request headers.
* @param {function} [callback] - available on the Client to support asynchronous requests. function is passed an nlobjServerResponse with the results.
* @return {nlobjServerResponse}
*
* @exception {SSS_UNKNOWN_HOST}
* @exception {SSS_INVALID_HOST_CERT}
* @exception {SSS_REQUEST_TIME_EXCEEDED}
* @exception {SSS_CONNECTION_CLOSED}
* @exception {SSS_CONNECTION_TIME_OUT}
* @exception {SSS_INVALID_URL}
* @exception {SSS_UNSUPPORTED_ENCODING}
*
* @since 2012.1
*/
exports.nlapiRequestURLWithCredentials = function (credentials, url, postdata, headers, method) { };
/**
* Return context information about the current user/script.
*
* @return {nlobjContext}
*
* @since 2007.0
*/
exports.nlapiGetContext = function () {
return {
getScriptId: () => random(1, 100).toString(),
getEnvironment: () => 'PRODUCTION', // TODO: Take from Test configuration environment variable.
getRemainingUsage: () => random(0, 10000).toString(),
};
};
/**
* Return the internal ID for the currently logged in user. Returns -4 when called from online forms or "Available without Login" Suitelets.
*
* @return {int}
*
* @since 2005.0
*/
exports.nlapiGetUser = function () { };
/**
* Return the internal ID for the current user's role. Returns 31 (Online Form User) when called from online forms or "Available without Login" Suitelets.
*
* @return {int}
*
* @since 2005.0
*/
exports.nlapiGetRole = function () { };
/**
* Return the internal ID for the current user's department.
*
* @return {int}
*
* @since 2005.0
*/
exports.nlapiGetDepartment = function () { };
/**
* Return the internal ID for the current user's location.
*
* @return {int}
*
* @since 2005.0
*/
exports.nlapiGetLocation = function () { };
/**
* Return the internal ID for the current user's subsidiary.
*
* @return {int}
*
* @since 2008.1
*/
exports.nlapiGetSubsidiary = function () { };
/**
* Return the recordtype corresponding to the current page or userevent script.
*
* @return {string}
*
* @since 2007.0
*/
exports.nlapiGetRecordType = function () { return random(1, 100).toString(); };
/**
* Return the internal ID corresponding to the current page or userevent script.
*
* @return {int}
*
* @since 2007.0
*/
exports.nlapiGetRecordId = function () { return random(1, 100); };
/**
* Send out an email and associate it with records in the system.
* Supported base types are entity for entities, transaction for transactions, activity for activities and cases, record|recordtype for custom records
* @governance 10 units
* @restriction all outbound emails subject to email Anti-SPAM policies
*
* @param {int} from internal ID for employee user on behalf of whom this email is sent
* @param {string, int} to email address or internal ID of user that this email is being sent to
* @param {string} subject email subject
* @param {string} body email body
* @param {string, string[]} cc copy email address(es)
* @param {string, string[]} bcc blind copy email address(es)
* @param {Object} records Object of base types -> internal IDs used to associate email to records. i.e. {entity: 100, record: 23, recordtype: customrecord_surveys}
* @param {nlobjFile[]} files array of nlobjFile objects (files) to include as attachments
* @param {boolean} notifySenderOnBounce controls whether or not the sender will receive email notification of bounced emails (defaults to false)
* @param {boolean} internalOnly controls or not the resultingMmessage record will be visible to non-employees on the Communication tab of attached records (defaults to false)
* @param {string} replyTo email reply-to address
* @return {void}
*
* @since 2007.0
*/
exports.nlapiSendEmail = function (from, to, subject, body, cc, bcc, records, files, notifySenderOnBounce, internalOnly, replyTo) {
const obj = {
from, to, subject, body, cc, bcc, records, files, notifySenderOnBounce, internalOnly, replyTo,
};
nlapiLogExecution('Debug', 'email:', JSON.stringify(obj, null, 2));
};
/**
* Sends a single on-demand campaign email to a specified recipient and returns a campaign response ID to track the email.
* @governance 10 units
* @restriction works in conjunction with the Lead Nurturing (campaigndrip) sublist only
*
* @param {int} campaigneventid internal ID of the campaign event
* @param {int} recipientid internal ID of the recipient - the recipient must have an email
* @return {int}
*
* @since 2010.1
*/
exports.nlapiSendCampaignEmail = function (campaigneventid, recipientid) { };
/**
* Send out a fax and associate it with records in the system. This requires fax preferences to be configured.
* Supported base types are entity for entities, transaction for transactions, activity for activities and cases, record|recordtype for custom records
* @governance 10 units
*
* @param {int} from internal ID for employee user on behalf of whom this fax is sent
* @param {string, int} to fax address or internal ID of user that this fax is being sent to
* @param {string} subject fax subject
* @param {string} body fax body
* @param {Object} records Object of base types -> internal IDs used to associate fax to records. i.e. {entity: 100, record: 23, recordtype: customrecord_surveys}
* @param {nlobjFile[]} files array of nlobjFile objects (files) to include as attachments
* @return {void}
*
* @since 2008.2
*/
exports.nlapiSendFax = function (from, to, subject, body, records, files) { };
/**
* Return field definition for a field.
*
* @param {string} fldnam the name of the field
* @return {nlobjField}
*
* @since 2009.1
*/
exports.nlapiGetField = function (fldnam) { };
/**
* Return field definition for a matrix field.
*
* @param {string} type matrix sublist name
* @param {string} fldnam matrix field name
* @param {int} column matrix field column index (1-based)
* @return {nlobjField}
*
* @since 2009.2
*/
exports.nlapiGetMatrixField = function (type, fldnam, column) { };
/**
* Return field definition for a sublist field.
*
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @param {int} [linenum] line number for sublist field (1-based) and only valid for sublists of type staticlist and list
* @return {nlobjField}
*
* @since 2009.1
*/
exports.nlapiGetLineItemField = function (type, fldnam, linenum) { };
/**
* Return an nlobjField containing sublist field metadata.
*
* @param {string} type matrix sublist name
* @param {string} fldnam matrix field name
* @param {int} linenum line number (1-based)
* @param {int} column matrix column index (1-based)
* @return {nlobjField}
*
* @since 2009.2
*/
exports.nlapiGetLineItemMatrixField = function (type, fldnam, linenum, column) { };
/**
* Return the value of a field on the current record on a page.
* @restriction supported in client and user event scripts only.
* @param {string} fldnam the field name
* @return {string}
*
* @since 2005.0
*/
exports.nlapiGetFieldValue = function (fldnam) {
switch (fldnam) {
case 'subsidiary':
return random(1, 9);
default:
return fldnam;
}
};
/**
* Set the value of a field on the current record on a page.
* @restriction supported in client and user event scripts only.
* @restriction synchronous arg is only supported in client SuiteScript
*
* @param {string} fldnam the field name
* @param {string} value value used to set field
* @param {boolean} [firefieldchanged] if false then the field change event is suppressed (defaults to true)
* @param {boolean} [synchronous] if true then sourcing and field change execution happens synchronously (defaults to false).
* @return {void}
*
* @since 2005.0
*/
exports.nlapiSetFieldValue = function (fldnam, value, firefieldchanged, synchronous) { return random(0, 50); };
/**
* Return the display value of a select field's current selection on the current record on a page.
* @restriction supported in client and user event scripts only.
* @param {string} fldnam the field name
* @return {string}
*
* @since 2005.0
*/
exports.nlapiGetFieldText = function (fldnam) { };
/**
* Set the value of a field on the current record on a page using it's label.
* @restriction synchronous arg is only supported in client SuiteScript
*
* @param {string} fldnam the field name
* @param {string} txt display name used to lookup field value
* @param {boolean} [firefieldchanged] if false then the field change event is suppressed (defaults to true)
* @param {boolean} [synchronous] if true then sourcing and field change execution happens synchronously (defaults to false).
* @return {void}
*
* @since 2005.0
*/
exports.nlapiSetFieldText = function (fldnam, txt, firefieldchanged, synchronous) { };
/**
* Return the values of a multiselect field on the current record on a page.
* @restriction supported in client and user event scripts only.
* @param {string} fldnam the field name
* @return {string[]}
*
* @since 2005.0
*/
exports.nlapiGetFieldValues = function (fldnam) { };
/**
* Set the values of a multiselect field on the current record on a page.
* @restriction supported in client and user event scripts only.
* @restriction synchronous arg is only supported in client SuiteScript
*
* @param {string} fldnam field name
* @param {string[]} values array of strings containing values for field
* @param {boolean} [firefieldchanged] if false then the field change event is suppressed (defaults to true)
* @param {boolean} [synchronous] if true then sourcing and field change execution happens synchronously (defaults to false).
* @return {void}
*
* @since 2005.0
*/
exports.nlapiSetFieldValues = function (fldnam, values, firefieldchanged, synchronous) { };
/**
* Return the values (via display text) of a multiselect field on the current record.
* @restriction supported in client and user event scripts only.
* @param {string} fldnam field name
* @return {string[]}
*
* @since 2009.1
*/
exports.nlapiGetFieldTexts = function (fldnam) { };
/**
* Set the values (via display text) of a multiselect field on the current record on a page.
* @restriction supported in client and user event scripts only.
* @restriction synchronous arg is only supported in client SuiteScript
*
* @param {string} fldnam field name
* @param {string[]} texts array of strings containing display values for field
* @param {boolean} [firefieldchanged] if false then the field change event is suppressed (defaults to true)
* @param {boolean} [synchronous] if true then sourcing and field change execution happens synchronously (defaults to false).
* @return {void}
*
* @since 2009.1
*/
exports.nlapiSetFieldTexts = function (fldnam, texts, firefieldchanged, synchronous) { };
/**
* Get the value of a matrix header field
*
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @param {int} column matrix column index (1-based)
* @return {string}
*
* @since 2009.2
*/
exports.nlapiGetMatrixValue = function (type, fldnam, column) { };
/**
* Set the value of a matrix header field
* @restriction synchronous arg is only supported in client SuiteScript
*
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @param {int} column matrix column index (1-based)
* @param {string} value field value for matrix field
* @param {boolean} [firefieldchanged] if false then the field change event is suppressed (defaults to true)
* @param {boolean} [synchronous] if true then sourcing and field change execution happens synchronously (defaults to false).
* @return {void}
*
* @since 2009.2
*/
exports.nlapiSetMatrixValue = function (type, fldnam, column, value, firefieldchanged, synchronous) { };
/**
* Get the current value of a sublist field on the current record on a page.
* @restriction supported in client and user event scripts only.
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @param {int} column matrix column index (1-based)
* @return {string} value
*
* @since 2009.2
*/
exports.nlapiGetCurrentLineItemMatrixValue = function (type, fldnam, column) { };
/**
* Set the current value of a sublist field on the current record on a page.
* @restriction supported in client and user event scripts only.
* @restriction synchronous arg is only supported in Client SuiteScript
*
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @param {int} column matrix column index (1-based)
* @param {string} value matrix field value
* @param {boolean} [firefieldchanged] if false then the field change event is suppressed (defaults to true)
* @param {boolean} [synchronous] if true then sourcing and field change execution happens synchronously (defaults to false).
* @return {void}
*
* @since 2009.2
*/
exports.nlapiSetCurrentLineItemMatrixValue = function (type, fldnam, column, value, firefieldchanged, synchronous) { };
/**
* Return the value of a sublist matrix field on the current record on a page.
* @restriction supported in client and user event scripts only.
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @param {int} linenum line number (1-based)
* @param {int} column column index (1-based)
* @param {string} value
*
* @since 2009.2
*/
exports.nlapiGetLineItemMatrixValue = function (type, fldnam, linenum, column) { };
/**
* Return the value of a sublist field on the current record on a page.
* @restriction supported in client and user event scripts only.
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @param {int} linenum line number (1-based)
* @return {string}
*
* @since 2005.0
*/
exports.nlapiGetLineItemValue = function (type, fldnam, linenum) { };
/**
* Return the value of a sublist field on the current record on a page.
* @restriction supported in client and user event scripts only.
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @param {int} linenum line number (1-based)
* @param {string} timezone [optional] value
* @return {string}
*
* @since 2013.2
*/
exports.nlapiGetLineItemDateTimeValue = function (type, fldnam, linenum, timezone) { };
/**
* Set the value of a sublist field on the current record on a page.
* @restriction supported in client and user event scripts only.
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @param {int} linenum line number (1-based)
* @param {string} value
* @retun {void}
*
* @since 2005.0
*/
exports.nlapiSetLineItemValue = function (type, fldnam, linenum, value) { };
/**
* Set the value of a sublist field on the current record on a page.
* @restriction supported in client and user event scripts only.
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @param {int} linenum line number (1-based)
* @param {string} datetime value
* @param {string} [timezone] value
* @retun {void}
*
* @since 2013.2
*/
exports.nlapiSetLineItemDateTimeValue = function (type, fldnam, linenum, value, timezone) { };
/**
* Return the label of a select field's current selection for a particular line.
*
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @param {int} linenum line number (1-based)
* @return {string}
*
* @since 2005.0
*/
exports.nlapiGetLineItemText = function (type, fldnam, linenum) { };
/**
* Return the 1st line number that a sublist field value appears in
*
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @param {string} val the value being queried for in a sublist field
* @return {int}
*
* @since 2009.2
*/
exports.nlapiFindLineItemValue = function (type, fldnam, val) { };
/**
* Return the 1st line number that a matrix field value appears in
*
* @param {string} type sublist name
* @param {string} fldnam matrix field name
* @param {int} column matrix column index (1-based)
* @param {string} val the value being queried for in a matrix field
* @return {int}
*
* @since 2009.2
*/
exports.nlapiFindLineItemMatrixValue = function (type, fldnam, column, val) { };
/**
* Return the number of columns for a matrix field
*
* @param {string} type sublist name
* @param {string} fldnam matrix field name
* @return {int}
*
* @since 2009.2
*/
exports.nlapiGetMatrixCount = function (type, fldnam) { };
/**
* Return the number of sublists in a sublist on the current record on a page.
* @restriction supported in client and user event scripts only.
* @param {string} type sublist name
* @return {int}
*
* @since 2005.0
*/
exports.nlapiGetLineItemCount = function (type) { return random(0, 50); };
/**
* Insert and select a new line into the sublist on a page or userevent.
*
* @param {string} type sublist name
* @param {int} [line] line number at which to insert a new line.
* @return{void}
*
* @since 2005.0
*/
exports.nlapiInsertLineItem = function (type, line) { };
/**
* Remove the currently selected line from the sublist on a page or userevent.
*
* @param {string} type sublist name
* @param {int} [line] line number to remove.
* @return {void}
*
* @since 2005.0
*/
exports.nlapiRemoveLineItem = function (type, line) { };
/**
* Set the value of a field on the currently selected line.
* @restriction synchronous arg is only supported in client SuiteScript
*
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @param {string} value field value
* @param {boolean} [firefieldchanged] if false then the field change event is suppressed (defaults to true)
* @param {boolean} [synchronous] if true then sourcing and field change execution happens synchronously (defaults to false).
* @return {void}
*
* @since 2005.0
*/
exports.nlapiSetCurrentLineItemValue = function (type, fldnam, value, firefieldchanged, synchronous) { };
/**
* Set the value of a field on the currently selected line.
* @restriction synchronous arg is only supported in client SuiteScript
*
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @param {string} value field value
* @param {string} timezone [optional] value
* @return {void}
*
* @since 2013.2
*/
exports.nlapiSetCurrentLineItemDateTimeValue = function (type, fldnam, value, timezone) { };
/**
* Set the value of a field on the currently selected line using it's label.
* @restriction synchronous arg is only supported in client SuiteScript
*
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @param {string} txt string containing display value or search text.
* @param {boolean} [firefieldchanged] if false then the field change event is suppressed (defaults to true)
* @param {boolean} [synchronous] if true then sourcing and field change execution happens synchronously (defaults to false).
* @return {void}
*
* @since 2005.0
*/
exports.nlapiSetCurrentLineItemText = function (type, fldnam, txt, firefieldchanged, synchronous) { };
/**
* Return the value of a field on the currently selected line.
*
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @return {string}
*
* @since 2005.0
*/
exports.nlapiGetCurrentLineItemValue = function (type, fldnam) { return random(0, 50); };
/**
* Return the value of a field on the currently selected line.
*
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @param {string} [timezone] value
* @return {string}
*
* @since 2013.2
*/
exports.nlapiGetCurrentLineItemDateTimeValue = function (type, fldnam, timezone) { };
/**
* Return the label of a select field's current selection on the currently selected line.
*
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @return {string}
*
* @since 2005.0
*/
exports.nlapiGetCurrentLineItemText = function (type, fldnam) { random(0, 50); };
/**
* Return the line number for the currently selected line.
*
* @param {string} type sublist name
* @return {int}
*
* @since 2005.0
*/
exports.nlapiGetCurrentLineItemIndex = function (type) { };
/**
* Select an existing line in a sublist.
*
* @param {string} type sublist name
* @param {int} linenum line number to select
* @return {void}
*
* @since 2005.0
*/
exports.nlapiSelectLineItem = function (type, linenum) { };
/**
* Save changes made on the currently selected line to the sublist.
*
* @param {string} type sublist name
* @return {void}
*
* @since 2005.0
*/
exports.nlapiCommitLineItem = function (type) { };
/**
* Cancel any changes made on the currently selected line.
* @restriction Only supported for sublists of type inlineeditor and editor
*
* @param {string} type sublist name
* @return {void}
*
* @since 2005.0
*/
exports.nlapiCancelLineItem = function (type) { };
/**
* Select a new line in a sublist.
* @restriction Only supported for sublists of type inlineeditor and editor
*
* @param {string} type sublist name
* @return {void}
*
* @since 2005.0
*/
exports.nlapiSelectNewLineItem = function (type) { };
/**
* Refresh the sublist table.
* @restriction Only supported for sublists of type inlineeditor, editor, and staticlist
* @restriction Client SuiteScript only.
*
* @param {string} type sublist name
* @return{void}
*
* @since 2005.0
*/
exports.nlapiRefreshLineItems = function (type) { };
/**
* Adds a select option to a scripted select or multiselect field.
* @restriction Client SuiteScript only
*
* @param {string} fldnam field name
* @param {string} value internal ID for select option
* @param {string} text display text for select option
* @param {boolean} [selected] if true then option will be selected by default
* @return {void}
*
* @since 2008.2
*/
exports.nlapiInsertSelectOption = function (fldnam, value, text, selected) { };
/**
* Removes a select option (or all if value is null) from a scripted select or multiselect field.
* @restriction Client SuiteScript only
*
* @param {string} fldnam field name
* @param {string} value internal ID of select option to remove
* @return {void}
*
* @since 2008.2
*/
exports.nlapiRemoveSelectOption = function (fldnam, value) { };
/**
* Adds a select option to a scripted select or multiselect sublist field.
* @restriction Client SuiteScript only
*
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @param {string} value internal ID for select option
* @param {string} text display text for select option
* @param {boolean} [selected] if true then option will be selected by default
* @return {void}
*
* @since 2008.2
*/
exports.nlapiInsertLineItemOption = function (type, fldnam, value, text, selected) { };
/**
* Removes a select option (or all if value is null) from a scripted select or multiselect sublist field.
* @restriction Client SuiteScript only
*
* @param {string} type sublist name
* @param {string} fldnam sublist field name
* @param {string} value internal ID for select option to remove
* @return {void}
*
* @since 2008.2
*/
exports.nlapiRemoveLineItemOption = function (type, fldnam, value) { };
/**
* Returns true if any changes have been made to a sublist.
* @restriction Client SuiteScript only
*
* @param {string} type sublist name
* @return {boolean}
*
* @since 2005.0
*/
exports.nlapiIsLineItemChanged = function (type) { };
/**
* Return an record object containing the data being submitted to the system for the currenr record.
* @restriction User Event scripts only
*
* @return {nlobjRecord}
*
* @since 2008.1
*/
exports.nlapiGetNewRecord = function () { return new record('test', { tranid: random(1, 100).toString() }); };
/**
* Return an record object containing the current record's data prior to the write operation.
* @restriction beforeSubmit|afterSubmit User Event scripts only
*
* @return {nlobjRecord}
*
* @since 2008.1
*/
exports.nlapiGetOldRecord = function () { };
/**
* Create an nlobjError object that can be used to abort script execution and configure error notification
*
* @param {string} code error code
* @param {string} details error description
* @param {boolean} [suppressEmail] if true then suppress the error notification emails from being sent out (false by default).
* @return {nlobjError}
*
* @since 2008.2
*/
exports.nlapiCreateError = function (code, details, suppressEmail) { return new Error(code); };
/**
* Return a new entry form page.
* @restriction Suitelets only
*
* @param {string} title page title
* @param {boolean} [hideHeader] true to hide the page header (false by default)
* @return {nlobjForm}
*
* @since 2008.2
*/
exports.nlapiCreateForm = function (title, hideHeader) { };
/**
* Return a new list page.
* @restriction Suitelets only
*
* @param {string} title page title
* @param {boolean} [hideHeader] true to hide the page header (false by default)
* @return {nlobjList}
*
* @since 2008.2
*/
exports.nlapiCreateList = function (title, hideHeader) { };
/**
* Return a new assistant page.
* @restriction Suitelets only
*
* @param {string} title page title
* @param {boolean} [hideHeader] true to hide the page header (false by default)
* @return {nlobjAssistant}
*
* @since 2009.2
*/
exports.nlapiCreateAssistant = function (title, hideHeader) { };
/**
* Load a file from the file cabinet (via its internal ID or path).
* @governance 10 units
* @restriction Server SuiteScript only
*
* @param {string, int} id internal ID or relative path to file in the file cabinet (i.e. /SuiteScript/foo.js)
* @return {nlobjFile}
*
* @since 2008.2
*/
exports.nlapiLoadFile = function (id) { return file.create({ id: `${id}.pdf`, fileType: 'PDF', contents: Math.ceil(Math.random() * 100).toString() }); };
/**
* Add/update a file in the file cabinet.
* @governance 20 units
* @restriction Server SuiteScript only
*
* @param {nlobjFile} file a file object to submit
* @return {int} return internal ID of file
*
* @since 2009.1
*/
exports.nlapiSubmitFile = function (file) { };
/**
* Delete a file from the file cabinet.
* @governance 20 units
* @restriction Server SuiteScript only
*
* @param {int} id internal ID of file to be deleted
* @return {id}
*
* @since 2009.1
*/
exports.nlapiDeleteFile = function (id) { };
/**
* Instantiate a file object (specifying the name, type, and contents which are base-64 encoded for binary types.)
* @restriction Server SuiteScript only
*
* @param {string} name file name
* @param {string} type file type i.e. plainText, htmlDoc, pdf, word (see documentation for the list of supported file types)
* @param {string} contents string containing file contents (must be base-64 encoded for binary types)
* @return {nlobjFile}
*
* @since 2009.1
*/
exports.nlapiCreateFile = function (name, type, contents) { };
/**
* Perform a mail merge operation using any template and up to 2 records and returns an nlobjFile with the results.
* @restriction only supported for record types that are available in mail merge: transactions, entities, custom records, and cases
* @restriction Server SuiteScript only
* @governance 10 units
*
* @param {int} id internal ID of template
* @param {string} baseType primary record type
* @param {int} baseId internal ID of primary record
* @param {string} [altType] secondary record type
* @param {int} [altId] internal ID of secondary record
* @param {Object} [fields] Object of merge field values to use in the mail merge (by default all field values are obtained from records) which overrides those from the record.
* @return {nlobjFile}
*
* @since 2008.2
*/
exports.nlapiMergeRecord = function (id, baseType, baseId, altType, altId, fields) { };
/**
* Print a record (transaction) gievn its type, id, and output format.
* @restriction Server SuiteScript only
* @governance 10 units
*
* @param {string} type print output type: transaction|statement|packingslip|pickingticket
* @param {int} id internal ID of record to print
* @param {string} [format] output format: html|pdf|default
* @param {Object} [properties] Object of properties used to configure print
* @return {nlobjFile}
*
* @since 2008.2
*/
exports.nlapiPrintRecord = function (type, id, format, properties) { };
/**
* Generate a PDF from XML using the BFO report writer (see http://big.faceless.org/products/report/).
* @restriction Server SuiteScript only
* @governance 10 units
*
* @param {string} input string containing BFO compliant XHTML
* @return {nlobjFile}
*
* @since 2009.1
*/
exports.nlapiXMLToPDF = function (input) { return file.create({ id: 'test.pdf', fileType: 'PDF', contents: input }); };
/**
* Create a template renderer used to generate various outputs based on a template.
* @restriction Server SuiteScript only
* @governance 10 units
*
* @param {string} type media type: pdf|html
* @param {string} [engineType] [optional]: default is freemarker/html
* @return {nlobjTemplateRenderer}
*
*/
exports.nlapiCreateTemplateRenderer = function () { };
/**
* Create an email merger used to assemble subject and body text of an email from a given
* FreeMarker template and a set of associated records.
* @restriction Server SuiteScript only
*
* @param {int} templateId internal ID of the template
* @return {nlobjEmailMerger}
*
* @since 2015.1
*/
exports.nlapiCreateEmailMerger = function (id) { };
/**
* Create an entry in the script execution log (note that execution log entries are automatically purged after 30 days).
*
* @param {string} type log type: debug|audit|error|emergency
* @param {string} title log title (up to 90 characters supported)
* @param {string} [details] log details (up to 3000 characters supported)
* @return {void}
*
* @since 2008.1
*/
exports.nlapiLogExecution = function (type, title, details) {
showLogs ? console.log(`Type:${JSON.stringify(type)} Title:${JSON.stringify(title)} Value: `, JSON.stringify(details)) : '';
};
/**
* Queue a scheduled script for immediate execution and return the status QUEUED if successfull.
* @restriction Server SuiteScript only
* @governance 20 units
*
* @param {string, int} script script ID or internal ID of scheduled script
* @param {string, int} [deployment] script ID or internal ID of scheduled script deployment. If empty, the first "free" deployment (i.e. status = Not Scheduled or Completed) will be used
* @param {Object} parameters Object of parameter name->values used in this scheduled script instance
* @return {string} QUEUED or null if no available deployments were found or the current status of the deployment specified if it was not available.
*
* @since 2008.1
*/
exports.nlapiScheduleScript = function (script, deployment, parameters) { return 'QUEUED'; };
/**
* Return a URL with a generated OAuth token.
* @restriction Suitelets and Portlets only
* @governance 20 units
*
* @param {string} ssoAppKey
* @return {string}
*
* @since 2009.2
*/
exports.nlapiOutboundSSO = function (ssoAppKey) { };
/**
* Loads a configuration record
* @restriction Server SuiteScript only
* @governance 10 units
*
* @param {string} type
* @return {nlobjConfiguration}
*
* @since 2009.2
*/
exports.nlapiLoadConfiguration = function (type) { };
/**
* Commits all changes to a configuration record.
* @restriction Server SuiteScript only
* @governance 10 units
*
* @param {nlobjConfiguration} setup record
* @return (void)
*
* @since 2009.2
*/
exports.nlapiSubmitConfiguration = function (setup) { };
/**
* Convert a String into a Date object.
*
* @param {string} str date string in the user's date format, timeofday format, or datetime format
* @param {string} format format type to use: date|datetime|timeofday with date being the default
* @return {date}
*
* @since 2005.0
*/
exports.nlapiStringToDate = function (str, format) {
const mDate = moment(str);
return mDate.isValid() ? mDate.toDate() : new Date();
};
/**
* Convert a Date object into a String
*
* @param {date} d date object being converted to a string
* @param {string} [formattype] format type to use: date|datetime|timeofday with date being the default
* @return {string}
*
* @since 2005.0
*/
exports.nlapiDateToString = function (d, formattype) { return `${d.toLocaleDateString()} ${d.toLocaleTimeString}`; };
/**
* Add days to a Date object and returns a new Date
*
* @param {date} d date object used to calculate the new date
* @param {int} days the number of days to add to this date object.
* @return {date}
*
* @since 2008.1
*/
exports.nlapiAddDays = function (d, days) {
return moment(d)
.add(days, 'days')
.toDate();
};
/**
* Add months to a Date object and returns a new Date.
*
* @param {date} d date object used to calculate the new date
* @param {int} months the number of months to add to this date object.
* @return {date}
*
* @since 2008.1
*/
exports.nlapiAddMonths = function (d, months) {
return moment(d)
.add(months, 'months')
.toDate();
};
/**
* Format a number for data entry into a currency field.
*
* @param {string} str numeric string used to format for display as currency using user's locale
* @return {string}
*
* @since 2008.1
*/
exports.nlapiFormatCurrency = function (str) { };
/**
* Encrypt a String using a SHA-1 hash function
*
* @param {string} s string to encrypt
* @return {string}
*
* @since 2009.2
*/
exports.nlapiEncrypt = function (s) { };
/**
* Escape a String for use in an XML document.
*
* @param {string} text string to escape
* @return {string}
*
* @since 2008.1
*/
exports.nlapiEscapeXML = function (input) {
return input.replace(/&/g, '\\&')
.replace(/</g, '\\<')
.replace(/>/g, '\\>')
.replace(/"/g, '\\"')
.replace(/'/g, "\\'");
};
/**
* Convert a String into an XML document. Note that in Server SuiteScript XML is supported natively by the JS runtime using the e4x standard (http://en.wikipedia.org/wiki/E4X)
* This makes scripting XML simpler and more efficient
*
* @param {string} str string being parsed into an XML document
* @return {document}
*
* @since 2008.1
*/
exports.nlapiStringToXML = function (str) { };
/**
* Convert an XML document into a String. Note that in Server SuiteScript XML is supported natively by the JS runtime using the e4x standard (http://en.wikipedia.org/wiki/E4X)
* This makes scripting XML data simpler and more efficient
*
* @param {document} xml document being serialized into a string
* @return {string}
*
* @since 2008.1
*/
exports.nlapiXMLToString = function (xml) { };
/**
* Validate that a given XML document conforms to a given XML schema. XML Schema Definition (XSD) is the expected schema format.
*
* @param {document} xmlDocument xml to validate
* @param {document} schemaDocument schema to enforce
* @param {string} schemaFolderId if your schema utilizes <import> or <include> tags which refer to sub-schemas by file name (as opposed to URL),
* provide the Internal Id of File Cabinet folder containing these sub-schemas as the schemaFolderId argument
* @throws {nlobjError} error containsing validation failure message(s) - limited to first 10
*
* @since 2014.1
*/
exports.nlapiValidateXML = function (xmlDocument, schemaDocument, schemaFolderId) { };
/**
* select a value from an XML node using XPath. Supports custom namespaces (nodes in default namespace can be refer