To prevent client side (Scriptable Checkout) scripts deployed on 'recalc function' from looping infinitely, users must use a 'control' variable to control the execution of the script's function. Users would need to use a custom field as the 'control' variable. The following code demonstrates the use of a custom field as 'control' variable:
function customRecalc(){
//condition to prevent script execution
if(nlapiGetFieldValue('custbody_execute') != 'T'){
//set field to prevent re-execution
nlapiSetFieldValue('custbody_execute','T');
try{
//Do some processing
int count = nlapiGetLineItemCount('item');
for(var i=1; i<=count; i++){
nlapiSelectLineItem('item',i);
nlapiSetCurrentLineItemValue('item','price',i,'2');
nlapiCommitLineItem('item');
}
}
finally{
//reset field to allow future execution of recalc function
nlapiSetFieldValue('custbody_execute','F');
}
}
}
No comments:
Post a Comment