Define Methods for HTTP Actions in SuiteScript
Learn to define HTTP action methods in SuiteScript backend models for effective data transactions in NetSuite.
TL;DR
A backend model in SuiteScript must define methods for handling HTTP actions, enabling effective data transactions with NetSuite's API. This article explains common practices using SuiteScript 1.0.
What is a Backend Model?
Backend models are JavaScript components that play a vital role in data interactions with NetSuite. They utilize SuiteScript functionalities to manage data operations, such as retrieving, creating, and validating records.
How to Define Methods for HTTP Actions?
Overview
When creating backend models, each HTTP action (such as GET, POST, or DELETE) needs a corresponding method. These methods manage data transactions through the SuiteScript API. The example below illustrates how to implement the search and create methods in a backend model using SuiteScript 1.0.
Example Code
Here’s an example of a backend model that defines methods to handle search and creation of records:
1"text-purple-400">define(2 'QuestionsAndAnswers.Model'3, ['SC.Model', 'Application']4, "text-purple-400">function (SCModel, Application)5{6 'use strict';7 8 "text-purple-400">return SCModel.extend({9 name: 'QuestionsAndAnswers',10 validation: {11 question: {required: true, msg: 'The question is required'}12 },13 14 search: "text-purple-400">function(page)15 {16 "text-purple-400">var filters = [17 "text-purple-400">new nlobjSearchFilter('custrecord_q_and_a_answer', null, 'isnot', '')18 ],19 columns = [20 "text-purple-400">new nlobjSearchColumn('custrecord_q_and_a_queston'),21 "text-purple-400">new nlobjSearchColumn('custrecord_q_and_a_answer'),22 "text-purple-400">new nlobjSearchColumn('created')23 ];24 25 "text-purple-400">return Application.getPaginatedSearchResults({26 record_type: 'customrecord_q_and_a',27 filters: filters,28 columns: columns,29 page: parseInt(page, 10) || 130 });31 },32 33 create: "text-purple-400">function(data)34 {35 "text-purple-400">this.validate(data);36 37 "text-purple-400">var question = nlapiCreateRecord('customrecord_q_and_a');38 question.setFieldValue('custrecord_q_and_a_queston', data.question);39 "text-purple-400">var question_id = nlapiSubmitRecord(question);40 41 "text-purple-400">return data;42 }43 });44});Breakdown of the Example
-
Search Method: This method is responsible for retrieving records. It sets up search filters and columns for querying data from NetSuite records.
- Filters: Use
nlobjSearchFilterto define conditions for the search. In this case, it filters for answers that are not empty. - Columns: Define the columns to retrieve using
nlobjSearchColumn. - Pagination: The method fetches paginated results to handle large datasets efficiently.
- Filters: Use
-
Create Method: This creates a new record in NetSuite. It validates the incoming data, prepares a new record, inserts the data, and submits the record.
Conclusion
Defining methods to handle HTTP actions in backend models is essential for effective data management in SuiteScript applications. By implementing these methods, developers can create robust solutions that interact seamlessly with NetSuite’s data.
Key Takeaways
- Every backend model must define methods for handling HTTP methods.
- The
searchandcreatemethods are fundamental for data manipulation. - Proper validation ensures data integrity before submitting records.
Source: This article is based on Oracle's official NetSuite documentation.
Frequently Asked Questions (4)
Does defining HTTP action methods in SuiteScript apply to both SuiteScript 1.0 and 2.0?
Do I need to validate data before creating a record in NetSuite using SuiteScript?
How does pagination work in the search method for SuiteScript backend models?
What are the functions of filters and columns in the search method using SuiteScript?
Was this article helpful?
More in SuiteScript
- Scheduling Map/Reduce Script Submissions in NetSuite
Learn how to schedule map/reduce scripts for one-time or recurring submissions in NetSuite, enhancing automation and efficiency.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
- Binary File Support in N/https Module for SuiteScript
SuiteScript enhances capabilities with binary file support in the N/https module, allowing improved data handling in external communications.
- Attach and Detach Operations in NetSuite 2026.1
Attach and detach operations for record relationships in NetSuite enhance data management and connectivity.
