Customize Virtual Export NSObject Response
I have a script I'm using in a MyAPI, where I'm querying a Saved Search in NetSuite. However, when I get the response, the fields returned are the column names from NetSuite, and not the actual field names. Is there a way to ensure a JSON response that returns the actual field names and not the labels. This will help in my mapping in another system when I query the information. I've pasted my script below with the id's removed. I had tried using a regular export in a similar script, but couldn't pass the relevant information to it, and found out on another post that it wasn't possible yet, so switched to the virtual export. Thanks.
SCRIPT (response after):
import { request, exports, imports, flows } from 'integrator-api'
function handleRequest (options) {
let NSObject;
let response = {};
let invokeExportResponse;
let exportResponse;
let email = options.body.records[0].email;
NSObject = return_NS_Export_Obj (options);
// Execute the export
try {
if(email !== ""){
invokeExportResponse = exports.runVirtual({export:NSObject});
} else {
invokeExportResponse = "Email is empty";
}
response.statusCode = 200;
}catch(e) {
invokeExportResponse = JSON.stringify(e);
response.statusCode = 400;
}// Create body response
response.body = {
exportResponse: invokeExportResponse
}
return {
statusCode: response.statusCode,
headers: { },
body: response.body
}
}
function return_NS_Export_Obj (options) {
let NSObject;
let email = options.body.records[0].email;
let brand = options.body.records[0].brand;
let subsidiary = options.body.records[0].subsidiary;
NSObject = {
"_connectionId": "removed",
"netsuite": {
"type": "restlet",
"skipGrouping": true,
"statsOnly": false,
"restlet": {
"recordType": "customer",
"searchId": "removed",
"criteria": [
{
"field": "email",
"operator": "contains",
"searchValue": email
},
{
"field": "custentity_cseg_brand",
"operator": "is",
"searchValue": brand
},
{
"field": "subsidiary",
"operator": "anyof",
"searchValue": subsidiary
},
{
"field": "isdefaultshipping",
"operator": "is",
"searchValue": "T"
}
]
},
"distributed": {
"disabled": false,
"forceReload": false,
"executionContext": [
"userinterface",
"webstore"
],
"executionType": [
"create",
"edit",
"xedit"
]
}
},
"adaptorType": "NetSuiteExport"
}
return NSObject;
}
RESPONSE GIVEN
{"exportResponse": {"data": [{"id": "","recordType": "customer","ID": "","Name": "","Phone": "","Email": "","Brand": "","Address": "","Office Phone": "","Fax": "","Primary Contact": "","Alt. Email": "","Default Shipping Address": "T","Default Billing Address": "T","Primary Subsidiary": "","First Name": "","Last Name": "","Shipping Address 1": "","Shipping Address 2": "","Shipping City": "BRUNSWICK","Shipping Country": "United States","Shipping Zip": "","Shipping State/Province": "GA","Shipping Phone": ""}],"dataURIs": ["removed"]}}
{"exportResponse": {"data": [{"id": "","recordType": "customer","phone": "","email": "","cseg_brand": "","subsidiary": "","firstname": "","lastname": "","custevent_addr1": "","custevent_country": "United States",}],"dataURIs": [""]}}
Comments
Chris Coppenbarger thanks for the post! I've moved it from the "Community basics" to the "Troubleshoot custom flows" forum for visibility.
Hi, The easiest way would be to set the custom field label in the NetSuite Saved Search to be the actual field name.
Bas van Ditzhuijzen
That's what someone in support suggested. It didn't seem to make sense as that's not what I was expecting. I did that, and it works for me for now.
I still can't get other items the way that I'm expecting, but it's probably just a NetSuite API implementation thing, not a Celigo thing. Too many hacky workarounds.
Please sign in to leave a comment.