i'm trying to write a Restlet to create a sales order in NetSuite and need put an item recordRef type in a field, but i don't know how can i get it, or how can i write it. Please, can you help me?
Here is the recordRef schema https://www.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2017_1/schema/other/recordref.html?mode=package
Next my script =>
function CreateNetSuiteOrder(requestBody) {
var salesOrder = record.create({
type: record.Type.SALES_ORDER,
isDynamic: true,
defaultValues: {
entity: 9999999999
}
});
salesOrder.setValue({ fieldId: 'trandate', value: new Date('5/07/2020') });
var subrec = salesOrder.getSubrecord({
fieldId: 'shippingaddress'
});
subrec.setValue({ fieldId: 'addr1', value: '123 street' });
subrec.setValue({ fieldId: 'city', value: 'city' });
subrec.setValue({ fieldId: 'state', value: 'state' });
subrec.setValue({ fieldId: 'zip', value: 'CA' });
subrec.setValue({ fieldId: 'addressee', value: 'John' });
subrec.setValue({ fieldId: 'attention', value: 'John' });
salesOrder.selectNewLine({
sublistId: 'item'
});
salesOrder.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value: // i should put RecordRef here
});
salesOrder.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
// value: item.quantity_order
value: 3
});
salesOrder.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'rate',
value: 34.0
});
salesOrder.commitLine({
sublistId: 'item'
});
salesOrder.save(
{
enableSourcing: false,
ignoreMandatoryFields: true
} )
A
RecordRef
is another class that exported in the NetSuite wsdl. It's used mostly in select-type fields where you can specify either the internal id or the text of the value you want to put in that field.I use some extension methods to make working with
RecordRef
s a bit easier. They look something like this:With this extension in place, the code above would look like this: