If you’d like to try deploying a NetSuite RESTlet script for the first time, then this article is for you.
RESTlet scripts prove to be very essential when coming to learn more about NetSuite integrations. They allow developers to write custom codes and lets one get and post data from external applications to NetSuite.
Below is a sample code you can copy and paste to start learning. What this code does is to get values from a NetSuite master data upon calling the URL.
/**
*@NApiVersion 2.x
*@NScriptType Restlet
*/
define(['N/record'],
function(record) {
function methodGet(datain) {
var recSupplier = record.load({
type: datain.rectype,
id: datain.recid
});
var RecordInfo = {};
RecordInfo.name = recSupplier.getValue({
fieldId: "entityid"
});
RecordInfo.parent = recSupplier.getValue({
fieldId: "companyname"
});
RecordInfo.legalname = recSupplier.getValue({
fieldId: "legalname"
});
RecordInfo.email = recSupplier.getValue({
fieldId: "email"
});
RecordInfo.phone = recSupplier.getValue({
fieldId: "phone"
});
return RecordInfo;
}
return {
get: methodGet
};
}
);
To deploy the RESTlet script, follow these steps:
- Copy the code above.
- Paste it over the IDE of your choice.
- Save it as a .js file.
- Log in to NetSuite and upload the JS file by going to Customization > Scripting > Scripts > New.
- Give your script a name.
- Click on Save.
- Click on “Deploy Script”.
- Ensure that the deployment page looks like the screenshot below.
Upon deployment, you will see the External URL in the page. Click on it to view and test the script functions: - When testing, make sure that parameters “rectype” and “recid” are passed, just as shown in this link:
LEACC Consulting is a team of NetSuite Certified Developers with IT experience solely dedicated to NetSuite technologies for eight years. We are experts in both SuiteScript 2.0 and SuiteScript 1.0. Our team has worked with 400+ NetSuite scripts and workflows combined. If you need some consulting help of how you can design your NetSuite scripts better, contact us by filling out this form or by commenting below.