I was stuck on a problem which probably plenty of new SuiteScript hackers will.
As writted on the official doc of SuiteScript p. 243, there's this JS for retrieve a record with GET method.
// Get a standard NetSuite record
function getRecord(datain) {
return nlapiLoadRecord(datain.recordtype, datain.id); // e.g recordtype="customer", id="769"
}
// .nl?script=22&deploy=1&recordtype=customer&id=769
But, when I was trying the EXACT snippet on NetSuite side, datain.recordtype
was undefined. (and return should only return text, BTW.)
Fortunately, I've found the solution by myself. Check my answer below.
I was stuck on a problem which probably plenty of new SuiteScript hackers will.
As writted on the official doc of SuiteScript p. 243, there's this JS for retrieve a record with GET method.
// Get a standard NetSuite record
function getRecord(datain) {
return nlapiLoadRecord(datain.recordtype, datain.id); // e.g recordtype="customer", id="769"
}
// http://rest.na1suite./app/site/hosting/restlet.nl?script=22&deploy=1&recordtype=customer&id=769
But, when I was trying the EXACT snippet on NetSuite side, datain.recordtype
was undefined. (and return should only return text, BTW.)
Fortunately, I've found the solution by myself. Check my answer below.
Share Improve this question edited Sep 11, 2020 at 22:41 quarks 35.4k82 gold badges308 silver badges547 bronze badges asked May 22, 2015 at 4:45 Zachary DahanZachary Dahan 1,49916 silver badges26 bronze badges 1- 1 I'm glad this Q/A has helped someone at least. My time wasn't wasted! – Zachary Dahan Commented May 22, 2015 at 4:54
1 Answer
Reset to default 5In this snippet (the same as above) ...
function getRecord(datain) {
return nlapiLoadRecord(datain.recordtype, datain.id); // e.g recordtype="customer", id="769"
}
// http://rest.na1suite./app/site/hosting/restlet.nl?script=22&deploy=1&recordtype=customer&id=769
—
SuiteScript was filling datain
not as an object nor JSON but as a string (for reason I still ignore.)
What you have to do so is just parse it before, then access the JSON with dot notation.
function getRecord(datain) {
var data = JSON.parse(datain); // <- this
return "This record is a " + data.recordtype + " and the ID is " + data.id;
}
// http://rest.na1suite./app/site/hosting/restlet.nl?script=22&deploy=1&recordtype=customer&id=769
I've changed the return statement in the solution because SuiteScript gives me error when I try to return something what isn't a text.
OR
As egrubaugh360 said, specify the Content-Type
is application/json
on your query script (the one who make call to your SuiteScript script)
So it'll give something like this if you're dealing with Node.js like me :
var options = {
headers: {
'Authorization': "<insert your NLAuth Authentification method here>",
"Content-Type" : "application/json" // <- this
}
}
https.request(options, function(results) {
// do something with results.
}
Hope this will help someone.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745564374a4633304.html
评论列表(0条)