Services and Backend Models in Custom Modules

Documentation article about Services and Backend Models in Custom Modules

·2 min read·View Oracle Docs

If you need to create a custom module to access NetSuite records, read the following topics to learn how:

Related Topics

General Notices

--- Context from https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_4623688578.html --- To use the data in a NetSuite record, you must determine how to represent the record as a JSON object. For example, a custom record containing a set of questions and answers may have the following structure:

  • record name - customrecord_q_and_a

  • custom field - custrecord_q_and_a_queston

  • custom field - custrecord_q_and_a_answer

A JSON object representing this custom record would look like the following:

javascript
{
"question": "A String with the question"
, "answer": "A String with the answer"
, "createdAt": "2016-03-31"
}

This example only requires name/value pairs representing each custom field and its value. However, depending on the complexity of the record you need to represent, a JSON object can be more complex. For example, a JSON object can contain arrays or nested objects.

After defining the formal structure of a JSON object, you can define the backend model that accesses the NetSuite record. See Create a Backend Model for more information.

Related Topics

General Notices

--- Context from https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_4623697867.html --- Backend models handle data transactions with NetSuite using SuiteScript.

Note:

The following code samples use SuiteScript 1.0 functions and objects only. These examples do not include SuiteScript 2.0 capabilities.

javascript
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
10 name: 'QuestionsAndAnswers'
11
12 , validation: {
13 question: {required: true, msg: 'The question is required'}
14 }
15
16 search: "text-purple-400">function(page)
17 {
18 "text-purple-400">var filters = [
19 "text-purple-400">new nlobjSearchFilter('custrecord_q_and_a_answer', null, 'isnot', '')
20 ]
21 , columns = [
22 "text-purple-400">new nlobjSearchColumn('custrecord_q_and_a_queston')
23 , "text-purple-400">new nlobjSearchColumn('custrecord_q_and_a_answer')
24 , "text-purple-400">new nlobjSearchColumn('created')
25 ];
26
27 "text-purple-400">return Application.getPaginatedSearchResults({
28 record_type: 'customrecord_q_and_a'
29 , filters: filters
30 , columns: columns
31 , page: parseInt(page, 10) || 1
32 });
33 }
34
35 create: "text-purple-400">function(data)
36 {
37
38 "text-purple-400">this.validate(data);
39
40 "text-purple-400">var question = nlapiCreateRecord('customrecord_q_and_a');
41 question.setFieldValue('custrecord_q_and_a_queston', data.question);
42 "text-purple-400">var question_id = nlapiSubmitRecord(question);
43
44 "text-purple-400">return data;
45 }
46 });
47});

This example demonstrates the following tasks that are common to all backend models. The following sections provide more detail about each task:

Define Dependencie

Frequently Asked Questions (4)

What is the purpose of defining a JSON object for a NetSuite record?
The purpose of defining a JSON object is to represent the NetSuite record structure. It includes name/value pairs for each custom field, and can include additional complexities like arrays or nested objects.
Are SuiteScript 2.0 features supported in backend models for NetSuite custom modules?
No, the code samples provided use SuiteScript 1.0 functions and objects only, and do not include SuiteScript 2.0 capabilities.
What are some common tasks required when creating a backend model in NetSuite?
Common tasks include defining dependencies, extending from SC.Model, defining a validation object, and defining methods to handle HTTP actions.
How do backend models handle HTTP requests in NetSuite custom modules?
Backend models typically handle HTTP requests by defining methods in the model to manage data transactions and perform operations on the NetSuite records.
Source: Services and Backend Models in Custom Modules Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in General

View all General articles →