Pedro Lourenço
Pedro Lourenço

Reputation: 1

How to create a Transfer Order from Work Order in Netsuite?

I'm new to scripting and I'm wondering if my code is correct in order to have a TO created whenever I have a WO entered in Netsuite:

define(['N/record',], function (record) {  function afterSubmit(context) {
if(context.type == 'delete'){
    log.debug('Exiting script', '...');
    return;
}
try{
var so = record.load({
    type:'workorder',
    id:context.newRecord.id
});
var so_items = so.getLineCount({sublistId:'item'});


// Create new Transfer Order if Record is On Create.
 var to_record = record.create({
    type:'transferorder',
    isDynamic:true
});

to_record.setValue({fieldId:'customform', value:136});
to_record.setValue({fieldId:'class', value:so.getValue('class')});
to_record.setValue({fieldId:'transferlocation', value:so.getValue('location')});

setLineItemsOnTO(so_items, to_record, so);

to_record.setValue({fieldId:'custbody_related_record', value:context.newRecord.id});
so.setValue({fieldId:'custbody_related_record', value:to_record.save()});
so.setValue({fieldId:'orderstatus',value:'B'});
so.save({ignoreMandatoryFields:true});
} catch(e){
    log.debug('Error Loading Record' + context.newRecord.id, e);
    return;     }

Upvotes: 0

Views: 589

Answers (1)

erictgrubaugh
erictgrubaugh

Reputation: 8847

There's no place where you're saving the Transfer Order you've created; you'll need a call to to_record.save() in order to commit it to the database.

Upvotes: 1

Related Questions