N/redirect Module Script Sample
The following script sample demonstrates how to use features of the N/redirect module.
Set a Redirect URL to a Newly Created Task Record
The following sample sets the redirect URL to a newly created task record. To set a redirect using a record ID, the record must have been previously submitted to NetSuite.
Note:
This sample script uses the require
function so that you can copy it into the SuiteScript Debugger and test it. You must use the define
function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.
/**
* @NApiVersion 2.x
*/
require(['N/record', 'N/redirect'], function(record, redirect) {
function redirectToTaskRecord() {
var taskTitle = 'New Opportunity';
var taskRecord = record.create({
type: record.Type.TASK
});
taskRecord.setValue('title', taskTitle);
var taskRecordId = taskRecord.save();
redirect.toRecord({
type: record.Type.TASK,
id: taskRecordId
});
}
redirectToTaskRecord();
});