How to update purchase order when item receipt is created or update

Hi, I am new to the SuiteScript. I have created User Event Script to update Item Received quantity on PO. Every single time when item receipt is created I have to go back to PO and click edit and save. Wondering if anyone know how to write back/update PO automatically when we receive Item/Item Receipt is created.

 

Thank you!

Rookie Asked on January 29, 2023 in SuiteScript.

/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
define([],
function () {
function beforeSubmit(context) {
try {

var totalQuantity = 0;
var totalQuantity_rec = 0;

var po = context.newRecord;
var itemCount = po.getLineCount(‘item’);

for (var i = 0; i < itemCount; i++) {

lineLevelQuantity = po.getSublistValue(‘item’, ‘quantity’, i)
if (lineLevelQuantity != ” && lineLevelQuantity != null) {
totalQuantity += parseInt(lineLevelQuantity);
}

}

for (var j = 0; j < itemCount; j++) {

lineLevelQuantity_rec = po.getSublistValue(‘item’, ‘quantityreceived’, j)
if (lineLevelQuantity_rec != ” && lineLevelQuantity_rec != null) {
totalQuantity_rec += parseInt(lineLevelQuantity_rec);
}

}

po.setValue(‘custbody80’, totalQuantity);
po.setValue(‘custbody81’, totalQuantity_rec);

} catch (e) {
log.debug({
title: ‘Error Details’,
details: e
})
}
}

return {
beforeSubmit: beforeSubmit
};
}
);

on January 29, 2023.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Become a Sponsor   Become a Sponsor