Lucas
05/10/2024, 2:53 AM// Global variable to prevent recursion
var IS_PROCESSING = false;
// Custom Recalculation function
function customRecalc(type, action) {
if (nlapiGetContext().getExecutionContext() !== 'webstore') {
return true;
}
nlapiLogExecution('DEBUG','type',type);
if (type === 'item' && (action === 'commit' || action === 'remove')) {
if (IS_PROCESSING) {
return true;
}
try {
IS_PROCESSING = true;
// The specific function you want to execute
nlapiLogExecution('DEBUG', 'action', action);
} catch (e) {
nlapiLogExecution('ERROR', 'Error in customRecalc', e.toString());
} finally {
IS_PROCESSING = false;
}
}
}
// Custom Field Change function
function customFieldChange(type, name) {
if (nlapiGetContext().getExecutionContext() !== 'webstore') {
return true;
}
if (name === 'shippingcost') {
if (IS_PROCESSING) {
return true;
}
IS_PROCESSING = true;
nlapiSetFieldValue('shippingcost', 0); // Set shipping cost to 0 under certain conditions
IS_PROCESSING = false;
}
}
// Custom Post Sourcing function
function customPostSourcing(type, name) {
if (nlapiGetContext().getExecutionContext() !== 'webstore') {
return true;
}
if (name === 'shippingtaxcode') {
if (IS_PROCESSING) {
return true;
}
IS_PROCESSING = true;
nlapiSetFieldValue('shippingtax1rate', 0); // Set shipping tax rate to 0 under certain conditions
IS_PROCESSING = false;
}
}
Steve Goldberg
05/10/2024, 9:28 AMLucas
05/10/2024, 9:29 AMLucas
05/10/2024, 9:31 AMLucas
05/10/2024, 9:32 AMLucas
05/10/2024, 9:36 AMLucas
05/11/2024, 1:13 PMSteve Goldberg
05/14/2024, 10:23 AMNElliott
05/15/2024, 8:03 AMLucas
05/15/2024, 6:33 PM// Global variable to prevent recursion
var IS_PROCESSING = false;
// Custom Recalculation function
function customRecalc(type, action) {
if (nlapiGetContext().getExecutionContext() !== 'webstore') {
return true;
}
if (type === 'item' && (action === 'commit' || action === 'remove')) {
if (IS_PROCESSING) {
return true;
}
try {
IS_PROCESSING = true;
// The specific function you want to execute
nlapiLogExecution('DEBUG', 'IS_PROCESSING initial', IS_PROCESSING);
nlapiLogExecution('DEBUG', 'action', action);
} catch (e) {
nlapiLogExecution('ERROR', 'Error in customRecalc', e.toString());
} finally {
IS_PROCESSING = false;
}
}
}
// Custom Field Change function
function customFieldChange(type, name) {
if (nlapiGetContext().getExecutionContext() !== 'webstore') {
return true;
}
if (name === 'shippingcost') {
if (IS_PROCESSING) {
return true;
}
IS_PROCESSING = true;
nlapiSetFieldValue('shippingcost', 0); // Set shipping cost to 0 under certain conditions
IS_PROCESSING = false;
}
}
// Custom Post Sourcing function
function customPostSourcing(type, name) {
if (nlapiGetContext().getExecutionContext() !== 'webstore') {
return true;
}
if (name === 'shippingtaxcode') {
if (IS_PROCESSING) {
return true;
}
IS_PROCESSING = true;
nlapiSetFieldValue('shippingtax1rate', 0); // Set shipping tax rate to 0 under certain conditions
IS_PROCESSING = false;
}
}
Steve Goldberg
05/16/2024, 8:56 AM// From this
if (IS_PROCESSING) {
return true;
}
// To this
if (IS_PROCESSING) {
return;
}
Could you change them to just return
please? Returning true
here could be messing with it when I think you need to be returning undefined
NElliott
05/16/2024, 8:59 AMvar IS_PROCESSING = false;
is outside your functions and I do not know if this code as a whole is being run repeatedly and if it is, that variable is potentially being reset to false each time before it's evaluated in the functions.
Sorry I'm not familiar with the script and architecture to know, I just hoped that talking about that might give you a 💡 moment.
However, if anyone can figure it for you @Steve Goldberg is your man 🙂Lucas
05/16/2024, 9:00 AMSteve Goldberg
05/16/2024, 9:14 AMLucas
05/16/2024, 9:17 AMif (IS_PROCESSING) {
return;
}
Lucas
05/16/2024, 9:18 AMLucas
05/16/2024, 9:19 AM// Global variable to prevent recursion
var IS_PROCESSING = false;
// Custom Recalculation function
function customRecalc(type, action) {
if (nlapiGetContext().getExecutionContext() !== 'webstore') {
return true;
}
if (type === 'item' && (action === 'commit' || action === 'remove')) {
if (IS_PROCESSING) {
return;
}
try {
IS_PROCESSING = true;
nlapiLogExecution('DEBUG', 'IS_PROCESSING initial', IS_PROCESSING);
nlapiLogExecution('DEBUG', 'action', action);
} catch (e) {
nlapiLogExecution('ERROR', 'Error in customRecalc', e.toString());
} finally {
IS_PROCESSING = false;
}
}
}
// Custom Field Change function
function customFieldChange(type, name) {
if (nlapiGetContext().getExecutionContext() !== 'webstore') {
return true;
}
if (name === 'shippingcost') {
if (IS_PROCESSING) {
return;
}
IS_PROCESSING = true;
nlapiSetFieldValue('shippingcost', 0); // Set shipping cost to 0 under certain conditions
IS_PROCESSING = false;
}
}
// Custom Post Sourcing function
function customPostSourcing(type, name) {
if (nlapiGetContext().getExecutionContext() !== 'webstore') {
return true;
}
if (name === 'shippingtaxcode') {
if (IS_PROCESSING) {
return;
}
IS_PROCESSING = true;
nlapiSetFieldValue('shippingtax1rate', 0); // Set shipping tax rate to 0 under certain conditions
IS_PROCESSING = false;
}
}
Steve Goldberg
05/16/2024, 9:22 AMSteve Goldberg
05/16/2024, 9:22 AMLucas
05/16/2024, 9:23 AMLucas
05/16/2024, 9:24 AMLucas
05/16/2024, 9:25 AM