Muhammad Hafiz
07/01/2022, 3:50 AMMarvin
07/01/2022, 4:05 AMMuhammad Hafiz
07/01/2022, 4:08 AMMuhammad Hafiz
07/01/2022, 4:08 AMfunction _get(context) {
doValidation([context.recordtype, context.id], ['recordtype', 'id'], 'GET');
return JSON.stringify(record.load({
type: context.recordtype,
id: context.id
}));
}
Marvin
07/01/2022, 4:17 AMrecord.load({
type: context.recordtype,
id: context.id
}).toJSON();
Muhammad Hafiz
07/01/2022, 4:30 AMMarvin
07/01/2022, 4:31 AMMuhammad Hafiz
07/01/2022, 4:31 AMMarvin
07/01/2022, 4:31 AMMarvin
07/01/2022, 4:36 AMconst lines = [];
search.create({
type: 'transaction',
columns: [
'tranid',
'trandate',
'item',
'amount'
],
filters: [
{name: 'type', operator: search.Operator.ANYOF, values: ['inventoryadjustment']}
]
}).run.each(result => {
lines.push({
tranid: result.getValue('tranid'),
trandate: result.getValue('trandate'),
item: result.getValue('item'),
amount: result.getValue('amount')
})
});
Marvin
07/01/2022, 4:37 AMMuhammad Hafiz
07/01/2022, 8:40 AMSyntax error: TypeError: redeclaration of formal parameter lines.My code is like this
function _get(lines) {
const lines = [];
search.create({
type: 'transaction',
columns: [
'tranid',
'trandate',
'item',
'amount'
],
filters: [
{name: 'type', operator: search.Operator.ANYOF, values: ['inventoryadjustment']}
]
}).run.each(result => {
lines.push({
tranid: result.getValue('tranid'),
trandate: result.getValue('trandate'),
item: result.getValue('item'),
amount: result.getValue('amount')
})
});
}
NElliott
07/01/2022, 9:24 AMMuhammad Hafiz
07/01/2022, 10:33 AM/**
*@NApiVersion 2.x
*@NScriptType Restlet
*/
define([
'N/record',
'N/search'
],
function(search){
function _get(lines) {
let lines = [];
search.create({
type: 'transaction',
columns: [
'tranid',
'trandate',
'item',
'amount'
],
filters: [
{name: 'type', operator: search.Operator.ANYOF, values: ['inventoryadjustment']}
]
}).run.each(result => {
lines.push({
tranid: result.getValue('tranid'),
trandate: result.getValue('trandate'),
item: result.getValue('item'),
amount: result.getValue('amount')
}
)
});
};
return {
get: _get
};
})
;
Muhammad Hafiz
07/01/2022, 10:33 AMCraig
07/01/2022, 11:43 AMCraig
07/01/2022, 11:44 AMMuhammad Hafiz
07/01/2022, 11:44 AMCraig
07/01/2022, 11:45 AMCraig
07/01/2022, 11:46 AMMuhammad Hafiz
07/01/2022, 11:47 AMCraig
07/01/2022, 11:49 AMCraig
07/01/2022, 11:49 AMMuhammad Hafiz
07/01/2022, 11:50 AMMuhammad Hafiz
07/01/2022, 11:53 AM/**
*@NApiVersion 2.x
*@NScriptType Restlet
*/
define([
'N/record',
'N/search'
],
function(search){
function _get(lines) {
let lineItems = [];
search.create({
type: 'transaction',
columns: [
'tranid',
'trandate',
'item',
'amount'
],
filters: [
{name: 'type', operator: search.Operator.ANYOF, values: ['inventoryadjustment']}
]
}).run.each(result => {
lineItems.push({
tranid: result.getValue('tranid'),
trandate: result.getValue('trandate'),
item: result.getValue('item'),
amount: result.getValue('amount')
}
)
});
};
return {
get: _get
};
})
;
Muhammad Hafiz
07/01/2022, 11:54 AMCraig
07/01/2022, 11:55 AMMuhammad Hafiz
07/01/2022, 11:55 AMCraig
07/01/2022, 11:56 AMCraig
07/01/2022, 11:58 AM/**
* @NApiVersion 2.1
* @NScriptType Restlet
*/
define(['N/search'],
(search) => {
const get = (requestParams) => {
let lines = [];
search.create({
type: 'transaction',
columns: [
'tranid',
'trandate',
'item',
'amount'
],
filters: [
{name: 'type', operator: search.Operator.ANYOF, values: ['inventoryadjustment']}
]
}).each(result => {
lines.push({
tranid: result.getValue('tranid'),
trandate: result.getValue('trandate'),
item: result.getValue('item'),
amount: result.getValue('amount')
}
)
});
}
return {get}
});
Muhammad Hafiz
07/01/2022, 12:02 PMJessicaL
07/01/2022, 12:09 PMMuhammad Hafiz
07/01/2022, 12:13 PMMarvin
07/01/2022, 4:43 PMsearch
was in fact calling the N/record
module instead of the N/search
module.
/**
*@NApiVersion 2.x
*@NScriptType Restlet
*/
define([
'N/record',
'N/search'
],
function(search)
Should be
/**
*@NApiVersion 2.x
*@NScriptType Restlet
*/
define([
'N/record',
'N/search'
],
function(record, search)
Craig
07/01/2022, 5:00 PMMarvin
07/01/2022, 6:01 PMMuhammad Hafiz
07/04/2022, 1:02 AMMarvin
07/04/2022, 7:38 PM.run()
.
You can do the search a couple ways and I prefer the way Craig wrote it unless there is a good reason to do another way.
const transaction_search = search.create({...});
transaction_search.run().each(result => {...});
or
search.create({...}).run().each(results => {...});
Try below.
/**
* @NApiVersion 2.1
* @NScriptType Restlet
*/
// eslint-disable-next-line no-undef
define(['N/search'],
/**
* @param{search} search
*/
(search) => {
/**
* Defines the function that is executed when a GET request is sent to a RESTlet.
* @param {Object} requestParams - Parameters from HTTP request URL; parameters passed as an Object (for all supported content types)
* @returns {string | Object} HTTP response body; returns a string when request Content-Type is 'text/plain'; returns an
* Object when request Content-Type is 'application/json' or 'application/xml'
* @since 2015.2
*/
// eslint-disable-next-line no-unused-vars
const get = (requestParams) => {
const lines = [];
search.create({
type: 'transaction',
columns: [
'tranid',
'trandate',
'item',
'amount'
],
filters: [
{ name: 'type', operator: search.Operator.ANYOF, values: ['inventoryadjustment'] }
]
})
.run()
.each(result => {
lines.push({
tranid: result.getValue('tranid'),
trandate: result.getValue('trandate'),
item: result.getValue('item'),
amount: result.getValue('amount')
});
return true;
});
};
return { get };
});
Muhammad Hafiz
07/05/2022, 1:19 AMMarvin
07/05/2022, 2:29 AMget
function.
return JSON.stringify(lines);
Muhammad Hafiz
07/05/2022, 2:37 AM/**
* @NApiVersion 2.1
* @NScriptType Restlet
*/
// eslint-disable-next-line no-undef
define(['N/search'],
/**
* @param{search} search
*/
(search) => {
/**
* Defines the function that is executed when a GET request is sent to a RESTlet.
* @param {Object} requestParams - Parameters from HTTP request URL; parameters passed as an Object (for all supported content types)
* @returns {string | Object} HTTP response body; returns a string when request Content-Type is 'text/plain'; returns an
* Object when request Content-Type is 'application/json' or 'application/xml'
* @since 2015.2
*/
// eslint-disable-next-line no-unused-vars
const get = (requestParams) => {
const lines = [];
search.create({
type: 'transaction',
columns: [
'tranid',
'trandate',
'item',
'amount'
],
filters: [
{ name: 'type', operator: search.Operator.ANYOF, values: ['inventoryadjustment'] }
]
})
.run()
.each(result => {
lines.push({
tranid: result.getValue('tranid'),
trandate: result.getValue('trandate'),
item: result.getValue('item'),
amount: result.getValue('amount')
});
return true;
});
return JSON.stringify(lines);
};
return { get };
});
Now it return an empty arrayMarvin
07/05/2022, 2:39 AMtype
in the columns. That way I can find the enum value.Muhammad Hafiz
07/05/2022, 2:46 AM