`define ( ['N/log', 'N/record'] ,` `f...
# suitescript
f
define ( ['N/log',          'N/record'] ,
function(log, record) {
function myBeforeLoad(context) {
var woRecord = context.newRecord;
var createdFromSO = woRecord.getValue({fieldId:'createdfrom'})
var soRecord = record.load({
type: record.Type.SALES_ORDER,
id: createdFromSO,
isDynamic: true,
});
var salesOrderValue = soRecord.getValue({fieldId:'tranid'});
var testForScript = woRecord.getValue({fieldId:'custbody_jh_test_for_script'});
woRecord.setValue({fieldId:'custbody_jh_test_for_script',value: salesOrderValue,ignoreFieldChange:true});
}
return {
beforeLoad: myBeforeLoad
};
});
I've been trying to set the transaction ID from my sales Order to my Work Order but unfortunately when I set the value it is blank for some reason. Is their a reason why in 2.0 ?
e
You can't set values on existing records in
beforeLoad
, only when they are new records.
f
Right.. So I've been testing it by creating New Sales Order but it's still blank for some reason. Once the Sales Order Creates the Work Order all the fields get sourced from the Sales Order but unfortunately not the field I want. It's been working when I don't load the Sales Order Record and just get the value from created from and set it there.
s
There's no reason to load the sales order just to retrieve a value from it, search.lookupFields should suffice to do that. Aside from that, canadian is right, beforeLoad is not for setting values.
👍 1
f
right I tried utilizing beforeSubmit but I needed to edit the Work order for the field to be populated.