In SCA we are commonly use suitescript 1 because of suitescript 2 has some limitations in SCA. We can also use suitescript 2 in SCA some scenarios it like suitelet we can get response of using the post and get method.
The flow of SCA is
From the manifest we need to change the entry point to service controller.
- Get or post method
- SCA service file
- Service controller
- Suitescript modal file
SuiteScript 1.0 to SuiteScript 2.x API Map added below
https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/chapter_4752722762.html
From SCA we can use suitescript 1 and suitescript 2 in suitelet and client script. We are using suitescript 2 in user event.
- For Create Record
We can create record and set the value.
nlapiCreateRecord(type, initializeValues)
var contactRecord = nlapiCreateRecord('contact', {
recordmode: 'dynamic'
});
contactRecord.setFieldValue(‘fistname’, 'Anik');
nlapiSubmitRecord(contactRecord);
- For load record
For loading the record and getting the values from customer record.also we can setting the value from customer record
For loading the record and getting the values from customer record.also we can setting the value from customer record
nlapiLoadRecord(type, id, initializeValues)
var record = nlapiLoadRecord('customer', 100)
var phone = record.getFieldValue('phone')
Record. setFieldValue(‘fistname’, 'Anik');
var numberOfAddresses = record.getLineItemCount('addressbook');
- For Submitting the record
nlapiSubmitRecord(record, doSourcing, ignoreMandatoryFields)
nlapiSubmitRecord(record, true);
- Send an Email
nlapiSendEmail(author, recipient, subject, body, cc, bcc, records, attachments, notifySenderOnBounce, internalOnly, replyTo)
- For Create an File
nlapiCreateFile(name, type, contents)
var newFile = nlapiCreateFile(fileData.name, 'PNGIMAGE', fileData.details);
newFile.setFolder(196355); //Web Site Hosting Files > Live Hosting Files > Model Images
var newFileId = nlapiSubmitFile(newFile);
Instruction to check when development
- Must need to add vendor name JJ
- How we can add console in netsuite
- If we need to extend the existing functionality of SCA we need to extend the modal file directly. Also, we need to add the entry point as a modal file.
- Remove the unwanted files in extensions. Example: configuration is not used in extension we can remove.
- The Log level scenario for adding log in suitescript.
Suitescript 2
Flow of the SCA using suitescript 2
- Get or post method
- Absolute URL of the suitescript 2 asset path redirect to suitescript 2 file
- Suitescript modal file
We can see the console of the suitescript 2 in only ss2 module of the ssp application. We can see the log in version 2 of ssp application.
- Create contact using suitescrpt 2
define(['N/record', 'N/runtime', 'N/search'], function (record, runtime, search) {
"use strict";
function ContactCreate(ctx) {
log.error("ctxctxctx ", ctx);
if (ctx.request.method === 'POST') {
var value = ctx.request.parameters ? (ctx.request.parameters) : null;
if (value != null) {
var object = value;
log.error("ctxctxctx ", object);
log.error("ctxctxctx ", object.firstname);
var objRecord = record.create({
type: record.Type.CONTACT,
isDynamic: true,
});
objRecord.setValue(
{
fieldId: 'firstname',
value: object.firstname
})
objRecord.setValue(
{
fieldId: 'email',
value: object.email
})
objRecord.setValue(
{
fieldId: 'entityid',
value: object.firstname
})
objRecord.save({
enableSourcing: true,
ignoreMandatoryFields: true
})
}
}
}
return {
service: ContactCreate
};
});