SPA Client Script Basic Examples using SuiteScript modules
The following code sample sends an email when the SPA is executed. It uses the N/email Module to create and send the email, and the N/runtime Module to get the internal ID of the current user and use it as the author of the email.
import email from 'N/email';
import runtime from 'N/runtime';
export const run = (context) => {
email.send({
author: runtime.getCurrentUser().id,
recipients: 'test@myCompany.com',
subject: 'SPA CS test',
body: 'N/email and N/runtime modules work OK'
});
};
The following example shows how to load an existing employee record using the N/record Module, and enter some value in the Notes field. Replace the value of the internal ID of the record with a valid value in your account.
import record from 'N/record';
export const run = (context) => {
var employee = record.load({
type : record.Type.EMPLOYEE,
id : -5
});
employee.setValue({
fieldId: 'comments',
value: 'Note added using an SPA'
});
employee.save();
};