MUHAMMAD MUBUSHER ASLAM
06/11/2021, 6:02 AM{
"type": "error.SuiteScriptError",
"name": "USER_ERROR",
"message": "This expense is already on a bill. Are you sure you want to edit it?",
"stack": [
"anonymous(N/serverRecordService)",
"afterSubmit(/SuiteScripts/Octavius App/vendorBillToItemReceiptUE.js:62)"
],
"cause": {
"type": "internal error",
"code": "USER_ERROR",
"details": "This expense is already on a bill. Are you sure you want to edit it?",
"userEvent": "aftersubmit",
"stackTrace": [
"anonymous(N/serverRecordService)",
"afterSubmit(/SuiteScripts/Octavius App/vendorBillToItemReceiptUE.js:62)"
],
"notifyOff": false
},
"id": "",
"notifyOff": false,
"userFacing": false
}
please have a look at the original code the one is throwing error
define(['N/record'], function (record) {
function afterSubmit(context) {
try {
if (context.type === context.UserEventType.CREATE) {
var currentRecord = context.newRecord;
var purchaseOrderId = currentRecord.getSublistValue({ sublistId: 'expense', fieldId: 'orderdoc', line: 0 });
if (purchaseOrderId) {
var lineExpanses = [];
var lineCount = currentRecord.getLineCount({ sublistId: 'expense' });
var TR_RECORD = record.transform({
fromType: record.Type.PURCHASE_ORDER,
fromId: purchaseOrderId,
toType: record.Type.ITEM_RECEIPT
});
var TR_LINES = TR_RECORD.getLineCount({ sublistId: 'expense' });
for (var i = 0; i < TR_LINES; i++) {
TR_RECORD.setSublistValue({ sublistId: 'expense', fieldId: 'markreceived', line: i, value: false });
}
for (var i = 0; i < lineCount; i++) {
var currentOrderLine = currentRecord.getSublistValue({ sublistId: 'expense', fieldId: 'orderline', line: i });
for (var j = 0; j < TR_LINES; j++) {
var receiptOrderLine = TR_RECORD.getSublistValue({ sublistId: 'expense', fieldId: 'orderline', line: j });
if (currentOrderLine == receiptOrderLine) {
TR_RECORD.setSublistValue({ sublistId: 'expense', fieldId: 'markreceived', line: j, value: true });
var _account = currentRecord.getSublistValue({ sublistId: 'expense', fieldId: 'account', line: i })
var _amount = currentRecord.getSublistValue({ sublistId: 'expense', fieldId: 'amount', line: i })
lineExpanses.push({
account: _account,
amount: _amount,
orderLine: currentOrderLine
});
}
}
}
var savedReceiptId = TR_RECORD.save({
enableSourceing: true
});
var dat = ' ';
var PO_RCD = record.load({ type: record.Type.PURCHASE_ORDER, id: purchaseOrderId });
var PO_LINES = PO_RCD.getLineCount({ sublistId: 'expense' });
for (var i = 0; i < lineCount; i++) {
var currentOrderLine = currentRecord.getSublistValue({ sublistId: 'expense', fieldId: 'orderline', line: i });
//dat = dat + 'currentOrderLine: ' + currentOrderLine + ' loopIndex:' + i;
for (var k = 0; k < PO_LINES; k++) {
var orderLine = PO_RCD.getSublistValue({ sublistId: 'expense', fieldId: 'line', line: k });
// might need to add more check account, amount, filter
if (currentOrderLine == orderLine) {
PO_RCD.setSublistValue({ sublistId: 'expense', fieldId: 'custcol_billed', line: k, value: true });
PO_RCD.setSublistValue({ sublistId: 'expense', fieldId: 'custcol_received', line: k, value: true });
dat = dat + ' PO OrderLine: ' + orderLine;
}
//dat = dat + ' orderLine: ' + orderLine + ' semiloopIndex:' + k;
}
}
var poorder = PO_RCD.save({
enableSourceing: false
});
log.debug({
title: 'ItemReceipt Id: ' + savedReceiptId + ' is created for PurchaseOrderId: ' + purchaseOrderId + ' existingPurchaseOrder: ' + poorder,
details: JSON.stringify(lineExpanses) + dat
});
}
}
}
catch (ex) {
log.debug({
title: 'Error creating ItemReceipt',
details: JSON.stringify(ex)
});
}
}
return { afterSubmit: afterSubmit };
});
battk
06/11/2021, 6:04 AMbattk
06/11/2021, 6:05 AMbattk
06/11/2021, 6:06 AMbattk
06/11/2021, 6:08 AMbattk
06/11/2021, 6:08 AMMUHAMMAD MUBUSHER ASLAM
06/11/2021, 6:19 AMbattk
06/11/2021, 6:22 AMbattk
06/11/2021, 6:23 AMbattk
06/11/2021, 6:23 AMMUHAMMAD MUBUSHER ASLAM
06/11/2021, 6:24 AMbattk
06/11/2021, 6:25 AMbattk
06/11/2021, 6:25 AMbattk
06/11/2021, 6:27 AMMUHAMMAD MUBUSHER ASLAM
06/11/2021, 10:16 AMbattk
06/11/2021, 10:18 AMbattk
06/11/2021, 10:18 AMMUHAMMAD MUBUSHER ASLAM
06/14/2021, 8:57 AMbattk
06/14/2021, 10:07 AMMUHAMMAD MUBUSHER ASLAM
06/15/2021, 12:33 AMbattk
06/15/2021, 12:36 AMbattk
06/15/2021, 12:36 AM