I am trying to add lines to a transfer order in Netsuite. I want to add them on the latest order created between two specific locations.
I am trying this:
var s = search.create({
type : search.Type.TRANSACTION,
columns : ['internalid'],
filters : [
["location","anyof","61"],
"AND",
["transferlocation","anyof","62"],
"AND",
["mainline","is","T"],
"AND",
["trandate","on","today"]
]
});
var resultSet = s.run();
var latestTO = resultSet[0];
But I get this error when I try adding a line to latestTO:
{"type":"error.SuiteScriptError","name":"UNEXPECTED_ERROR","message":null,"stack":["anonymous(N/recordImpl)","onAction(/SuiteScripts/TEST.js:67)"],"cause":{"type":"internal error","code":"UNEXPECTED_ERROR","details":null,"userEvent":null,"stackTrace"
My script works if I "hardcode" the internalID of the latest transfer order.
Any ideas?
If you are trying to create a Saved Search to access Transfer Orders, you can use SORT BY
function. You can sort using Date Created in descending order.
I would suggest you to create the Saved Search and test all your requirements. Later you can export this Saved Search as a script and use it in your code.
In order to get the latest Transfer Order value, you simply need to include InternalID column in your results tab.
columns : ['internalid']
Later, you'll have to execute this Saved Search using script.
var s = search.create({
type : search.Type.TRANSACTION,
columns : ['internalid'],
filters : [
["location","anyof","61"],
"AND",
["transferlocation","anyof","62"],
"AND",
["mainline","is","T"],
"AND",
["trandate","on","today"]
]
});
var searchResultCount = s.runPaged().count;
log.debug("s result count",searchResultCount);
s.run().each(function(result){
// .run().each has a limit of 4,000 results
return true;
});
var searchResult = s.run().getRange({start:0,end:999});
Variable searchResultCount
stores the total number of results
Variable searchResult
contains all the data
In order to get recently created TO, simply fetch the first value.
for(var j=0;j<1;j++) {
var latestTO = searchResult[j].getValue({name:'internalid'});;
}
Variable latestTO will now have the internalID. Use this to load the record.
Let me know in case of any issues in the comment section.
Another problem is if i hardcode my variabel latestTO, as:
var latestTO = '1337';
and make the update:
var TO = record.load({
type: 'transferOrder',
id: latestTO,
isDynamic: true
});
Nothing happens.
But if I do:
var TO = record.load({
type: 'transferOrder',
id: 1337,
isDynamic: true
});
It works...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.