Ok, I've written a pretty simple (I thought) script for what I thought would be a pretty simple process. We use a custom service item (Assembly Labour) as a member item for Assemblies to go back later and add labour cost. The item is defaulted to 1 in members and is a $ unit.
One of our accounting dept's chores is at the end of the month to allocate labour logged to WO's to the resultant assemblies.
My script runs in Custom Code on the Assembly form - it does a great job changing the Assembly quantity to a calculated amount pulled in from the Work order, but when saving the Assembly, it doesn't actually hit the GL - GL Impact shows the default amount (*quantity of course).
Here's the script -
function UpdateLabourQuantity()
{
var line = nlapiFindLineItemValue('component','item',6143); //6143 being the assembly labour item
var labour = nlapiGetFieldValue('custbody305'); //calculated labour amount from WO
nlapiSetLineItemValue('component','quantity',line,labour);
nlapiCommitLineItem('component');
}
Initially I didn't have the call to commit the line item, because the user after creating the build still has to save the record - so I thought as long as the value is changed (and it is - it saves on the build) it would "count." I also had a return true line as I was running this on the Save Record Function as I wanted it to be the last thing that happened (and users not to mess with changing it). After learning the GL was being updated, I changed to Page Init function and added the commit line item, but this doesn't work either.Again, the field is updating fine, and I'm having a hard time wrapping my head around the difference between scripting the field change and manually entering the value. Should mention I'm new at this so probably missing something obvious - anyone care to tell me what it is? many thanks!