I am stumped. I am calling the below 'getAvailabl...
# suitescript
m
I am stumped. I am calling the below 'getAvailableLabor' function with the 'pageInit' function. This works perfectly in Firefox but produces 0.00 in Chrome. Anyone know why this would happen?
function pageInit(context) {
   
try {
 
var currAWP = context.currentRecord;
    
hideAmountSublist(context);
    
currAWP.setValue({
        
fieldId: 'custbody_avail_labor',
        
value: getAvailableLabor(currAWP)
    
});
    
currAWP.getField({fieldId: 'custbody_avail_labor'}).isDisabled = true;
   
} catch (e) {
       
log.error(e.message);
   
}
}
function getAvailableLabor (currAWP) {
    
try{
        
var clockInTime = (currAWP.getValue({
            
fieldId: 'custbody_clock_in_time'
        
}));
        
var clockOutTime = (currAWP.getValue({
            
fieldId: 'custbody_clock_out_time'
        
}));
        
var serviceChannelOnsite = (currAWP.getValue({
            
fieldId: 'custbody_sc_time_onsite'
        
}));
        
var availLabor = (((clockOutTime - clockInTime)/3600000)*60);
        
if(serviceChannelOnsite){
            
availLabor = (serviceChannelOnsite*60);
        
}
        
return availLabor.toFixed(2);
    
}catch (e){
        
log.error (e.message);
    
}
 
}
l
You can actually put debugger to monitor every variable to find the unexpected result
just use
debugger
within your
getAvailableLabor
and open chrome dev tool via
f12
m
I figured out that Chrome is executing the function before all the fields source on the form.
Could I use setTimeout to wait a couple seconds?
l
@MoCheeks you could, but I would not doing that