Reputation: 7
I'm currently trying to build a RESTlet script that will run daily to sync new work order data over from NetSuite to another web application (Tulip) for production. I am attempting to get the itemid for an assembly item in the work orders so that I can find its equivalent in a data table in Tulip.
Currently, I can output the item's record from the work order as a string, but I've found that Firstly, this script outputs for each work order 6 times, one for each component of the assembly item, and additionally, even if I get the right one, I'm unsure how to leverage the item record ID output in the script to find the itemid from the item record.
If I attempt to use nlapiSearchRecord()
to then find the item record by the itemid, so that I can pull the correct data, I always receive a null return.
Looking at the Execution log, I receive the following error:
Filter expecting numeric value was removed, as non-numeric value 'nlobjSearchColumn(item, null, null, type=select)' was provided.
I've looked through google and the 1.0 API documentation to try to find a method for getting a value from the subrecord, but I'm stuck.
Here is the current version of the script, with which I'm pulling the tranid, status, and the assemblyitem ID:
function getWOSoftLock() {
var dataoutput = nlapiSearchRecord(
'workorder',
null,
new nlobjSearchFilter('status', null, 'is', 'WorkOrd:B'),
[
new nlobjSearchColumn('tranid'),
new nlobjSearchColumn('status'),
new nlobjSearchColumn('item')
]
);
if(!dataoutput) {
nlapiLogExecution('AUDIT', 'No released work orders');
return [];
}
var mainreturn = dataoutput.map(function(res){
return {
tranid:res.getValue('tranid'),
status:res.getValue('status'),
item:res.getValue('item')
};
});
return mainreturn;
}
Can anyone point me towards how to pull subrecord data from the 'item' field when doing a search? I apologize if this is a daft question, I'm new to this and sort of ripping my hair out trying to figure it out.
Upvotes: 0
Views: 673
Reputation: 5276
this script outputs for each work order 6 times
Add a filter for Main Line = Yes so that only the header information is returned to avoid this. This will give one line per record, with only the assembly item shown and filter out the component lines.
I'm unsure how to leverage the item record ID output in the script to find the itemid from the item record.
You can get this by simply using res.getText('item')
instead of res.getValue('item')
. Generally, any select (list/record) field returned in a search has both getValue()
and getText()
methods available. getValue()
will return the internal id and getText()
will return the display value of the same field.
Upvotes: 0
Reputation: 7
Okay, so I've come up with a solution that works well enough in my situation.
Since I am able to utilize the NetSuite record ID for the inventory item to look it up, and I know I can access that item as 'assemblyitem' if the record has been loaded, I created a for loop that runs through each work order found in the search, loads it, and pulls the data I need.
Here's the early implementation in case this is helpful to somebody else:
function getWOSoftLock() {
var dataoutput = nlapiSearchRecord(
'workorder',
null,
new nlobjSearchFilter('status', null, 'is', 'WorkOrd:B'),
[
new nlobjSearchColumn('tranid'),
new nlobjSearchColumn('status'),
new nlobjSearchColumn('item'),
]
);
if(!dataoutput) {
nlapiLogExecution('AUDIT', 'No released work orders');
return [];
}
for (var i = 0; i < dataoutput.length; i++)
{
var woid = dataoutput[i].getId();
var worecord = nlapiLoadRecord('workorder', woid);
var assemblyid = worecord.getFieldValue('assemblyitem');
var parsedoutput = {"filID":assemblyid};
}
return parsedoutput;
}
I'll have to parse all of the data I want to pull and output it as an array, but this works for me.
Upvotes: 0