Netsuite Code Snippets - By Shayan Shaikh
The essential collection of Netsuite Code Snippets and commands.
Snippets
Snippet |
Renders |
Version |
ns-fun |
NS Simple Function |
V1 |
ns-class |
NS Class Function |
V1 |
ns-arrow-fun |
NS Arrow Function |
V1 |
ns-udb |
NS Utility Debug |
V1 |
ns-ua |
NS Utility Audit |
V1 |
ns-ue |
NS Utility Emergency |
V1 |
ns-ute |
NS Utility Throw Exception |
V1 |
ns-uex |
NS Utility Exception |
V1 |
ns-extend-cc |
Extend Connector Common script |
V1 |
ns-extend-fcf |
Extend Client Factory script |
V1 |
ns-extend-iel |
Extend Item Export script |
V1 |
ns-script-ue |
NS Userevent Script |
V1 |
ns-copy-lib |
Copy Script Libraries |
V1 |
ns-search-rec |
Function To Search The Record Existance |
V1 |
ns-upsert-rec |
NS Create/Load Record |
V1 |
ns-fun-v2 |
NS Simple Function |
V2 |
ns-class-v2 |
NS Class Function |
V2 |
ns-arrow-fun-v2 |
NS Arrow Function |
V2 |
ns-udb-v2 |
NS Utility Debug |
V2 |
ns-ua-v2 |
NS Utility Audit |
V2 |
ns-ue-v2 |
NS Utility Emergency |
V2 |
ns-ute-v2 |
NS Utility Throw Exception |
V2 |
ns-uex-v2 |
NS Utility Exception |
V2 |
ns-load-so-v2 |
Load and Submit Record |
V2 |
ns-trans-so-v2 |
Transform Record |
V2 |
ns-upsert-rec-v2 |
NS Create/Load Record |
V2 |
ns-search-rec-v2 |
Function To Search The Record Existance |
V2 |
Full Expansions
ns-arrow-fun | NS Arrow Function
/**
* @description
*/
const | = () => {
const logTitle = 'TM_FILENAME => |';
try {
Utility.logDebug(logTitle, 'START');
Utility.logDebug(logTitle, 'END');
} catch (e) {
Utility.logException(logTitle, e);
}
}
ns-fun | NS Class Function
| () {
const logTitle = 'TM_FILENAME => |';
try {
Utility.logDebug(logTitle, 'START');
Utility.logDebug(logTitle, 'END');
} catch (e) {
Utility.logException(logTitle, e);
}
}
ns-fun | NS Simple Function
function | () {
const logTitle = 'TM_FILENAME => |';
try {
Utility.logDebug(logTitle, 'START');
Utility.logDebug(logTitle, 'END');
} catch (e) {
Utility.logException(logTitle, e);
}
}
ns-copy-lib | Copy Script Libraries
let fileForDependencies = nlapiLoadRecord("scheduledscript", 'ORIGIN_SCRIPT_ID');
let myScript = nlapiLoadRecord("scheduledscript", 'YOUR_SCRIPT_ID');
let librariesCount = fileForDependencies.getLineItemCount("libraries");
for (let i = 0; i < librariesCount; i++) {
let scriptfile = fileForDependencies.getLineItemValue('libraries', 'scriptfile', i + 1);
myScript.setLineItemValue('libraries', 'scriptfile', i + 1, scriptfile);
}
nlapiSubmitRecord(myScript);
ns-search-rec | Function To Search The Record Existance
/**
* @param {} el
* @description
*/
const isRecordExist = (el) => {
const logTitle = 'TM_FILENAME => isRecordExist';
try {
const recordSearch = nlapiSearchRecord(
'RECORD_ID',
null,
[['FIELD_ID', 'is', el]],
[new nlobjSearchColumn('internalid').setSort(false)]
);
Utility.logDebug(logTitle, JSON.stringify({ recordSearch }));
return recordSearch ? recordSearch[0].getValue('internalid') : false;
} catch (e) {
Utility.logException(logTitle, e);
}
}
ns-upsert-rec | NS Create/Load Record
/**
* @param {} recordId
* @description
*/
const upsertRecord = (recordId) => {
const logTitle = 'TM_FILENAME => upsertRecord';
try {
const rec = recordId ? nlapiLoadRecord('RECORD_ID', recordId) : nlapiCreateRecord('RECORD_ID');
rec.setFieldValue('FIELD_NAME', 'VALUE');
return nlapiSubmitRecord(rec, true);
} catch (e) {
Utility.logException(logTitle, e);
}
};
ns-arrow-fun-v2 | NS Arrow Function
/**
* @description
*/
const | = () => {
const logTitle = 'TM_FILENAME => |';
try {
utility.logDebug({ title: logTitle, details: 'START' });
utility.logDebug({ title: logTitle, details: 'END' });
} catch (e) {
utility.logException({ title: logTitle, details: e });
}
}
ns-fun-v2 | NS Class Function
| () {
const logTitle = 'TM_FILENAME => |';
try {
utility.logDebug({ title: logTitle, details: 'START' });
utility.logDebug({ title: logTitle, details: 'END' });
} catch (e) {
utility.logException({ title: logTitle, details: e });
}
}
ns-fun-v2 | NS Simple Function
function | () {
const logTitle = 'TM_FILENAME => |';
try {
utility.logDebug({ title: logTitle, details: 'START' });
utility.logDebug({ title: logTitle, details: 'END' });
} catch (e) {
utility.logException({ title: logTitle, details: e });
}
}
ns-udb | NS Utility Debug
Utility.logDebug(logTitle, JSON.stringify({ | }));
ns-ua | NS Utility Audit
Utility.logAudit(logTitle, JSON.stringify({ | }));
ns-ue | NS Utility Emergency
Utility.logEmergency(logTitle, JSON.stringify({ | }));
ns-ute | NS Utility Throw Exception
Utility.throwException(logTitle, JSON.stringify({ | }));
ns-uex | NS Utility Exception
Utility.logException(logTitle, JSON.stringify({ | }));
ns-udb-v2 | NS Utility Debug
utility.logDebug({ title: logTitle, details: JSON.stringify({ | })});
ns-ua-v2 | NS utility Audit
utility.logAudit({ title: logTitle, details: JSON.stringify({ | })});
ns-ue-v2 | NS utility Emergency
utility.logEmergency({ title: logTitle, details: JSON.stringify({ | })});
ns-ute-v2 | NS utility Throw Exception
utility.throwException({ title: logTitle, details: JSON.stringify({ | })});
ns-uex-v2 | NS utility Exception
utility.logException({ title: logTitle, details: JSON.stringify({ | })});
ns-get-value-v2 | NS Get Value V2
|.getValue({ fieldId: '|' });
ns-set-value-v2 | NS Set Value V2
|.setValue({ fieldId: '|', value: | });
ns-get-sublistvalue-v2 | NS Set Sublist Value V2
|.getSublistValue({ sublistId: '|', fieldId: '|', line: | });
ns-set-subvalue-v2 | NS Get Sublist Value V2
|.setSublistValue({ sublistId: '|', fieldId: '|', line: |, value: | });
ns-load-so-v2 | NS Load Sales Order V2
const | = |.load({
type: 'salesorder',
id: |
});
|.setValue({ fieldId: '|', value: | });
const |Id = |.save({
enableSourcing: false,
ignoreMandatoryFields: true
});
const | = |.transform({
fromType: 'salesorder',
fromId: |,
toType: '|'
});
|.setValue({ fieldId: '|', value: | });
const |Id = |.save({
enableSourcing: true,
ignoreMandatoryFields: true
});
ns-search-rec-v2 | Function To Search The Record Existance
/**
* @param {} el
* @description
*/
function isRecordExist(el) {
const logTitle = 'TM_FILENAME => isRecordExist';
try {
const filExp = [['FIELD_ID', 'is', el]];
const columns = [
search.createColumn({
name: 'internalid'
})
];
const recordSearch = search.create({
type: 'RECORD_ID',
filters: filExp,
columns
});
let internalId = false;
recordSearch.run().each(function (el) {
internalId = el.getValue({ name: 'internalid' });
});
return internalId;
} catch (e) {
utility.logException({ title: logTitle, details: JSON.stringify({ e }) });
return false;
}
}
ns-upsert-rec-v2 | NS Create/Load Record
/**
* @param {*} recordId
* @returns
*/
function upsertRecord(recordId) {
const logTitle = 'TM_FILENAME => upsertRecord';
try {
const record = recordId ? rec.load({ type: 'RECORD_ID', id: recordId }) : rec.create({ type: 'RECORD_ID' });
record.setValue({ fieldId: 'FIELD_NAME', value: 'VALUE' });
return record.save();
} catch (e) {
utility.logException({ title: logTitle, details: JSON.stringify(e) });
return false;
}
}
Thank You! ❤️
Author Email: shayanshaikh996@gmail.com
© 2022 Shayan Shaikh.