Nour Khaled
05/20/2025, 8:49 AMCeligo AI
05/20/2025, 8:49 AMAI generated answer (using internal Slack threads):To detect changes in item average cost in SuiteScript, you can use a User Event (UE) script or a Scheduled script. In a User Event script, you can capture the old and new average cost in the beforeSubmit and afterSubmit events respectively. You can then compare these values to detect any changes. Here is a sample code snippet:
javascript
function beforeSubmit(type){
if (type == 'edit'){
var oldRecord = nlapiGetOldRecord();
var oldAvgCost = oldRecord.getFieldValue('averagecost');
nlapiSetFieldValue('custitem_old_average_cost', oldAvgCost);
}
}
function afterSubmit(type){
if (type == 'edit'){
var newRecord = nlapiGetNewRecord();
var newAvgCost = newRecord.getFieldValue('averagecost');
var oldAvgCost = newRecord.getFieldValue('custitem_old_average_cost');
if (oldAvgCost != newAvgCost){
// Average cost has changed
// Perform necessary actions
}
}
}
In a Scheduled script, you can periodically check the average cost of items and compare it with the previously stored value. If there is a change, you can perform necessary actions.
Please note that the 'averagecost' field is not available in all record types. You might need to use a search to get this value.
Also, if you want to capture the location-specific average cost, you might need to use a search with 'locationaveragecost' field. This field might not be available in the SuiteScript browser, but it should be available for searches.
******
Disclaimer:
This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes.
******Celigo AI
05/20/2025, 8:49 AMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.796072841
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.795894802
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.781251848
Celigo AI
05/20/2025, 8:49 AM