Hi team,
We have an Interactive Grid which has column A,B,C,D and a Page Item called InputNum.
We have a Use Case in that we would like to set a value in the column D of an Interactive Grid directly whenever A,B,C or InputNum is updated. So suppose we have row 3 and we updated the column A of row 3, the column D of row 3 will be calculated and updated using A,B,C and InputNum. It is calculated as (a - b - c) / InputNum;
The requirement is that the update is to be done on Javascript side.
We do not want to allow the user to change the value of Column D so we used type DisplayOnly for column D. But we encountered the following isses:
ISSUE 1
Upon accessing this page, when we insert a new row on the front end and updated A,B,C or InputNum, we got an error saying
desktop_all.min.js?v=24.2.6:7 Error in model listener. Error: Set value not allowed for field at Object.setValue (modelViewBase.min.js?v=24.2.6:4:26097) at t.<computed>.<computed>._setModelValue (modelViewBase.min.js?v=24.2.6:5:26810) at t.each.r.<computed> [as setModelValue] (desktopall.min.js?v=24.2.6:41:2898) at t.<computed>.<computed>.setActiveRecordValue (modelViewBase.min.js?v=24.2.6:5:5416) at t.each.r.<computed> [as setActiveRecordValue] (desktop_all.min.js?v=24.2.6:41:2898) at HTMLDivElement.<anonymous> (widget.grid.min.js?v=24.2.6:4:28912) at HTMLDivElement.dispatch (desktop_all.min.js?v=24.2.6:5:43125) at v.handle (desktop_all.min.js?v=24.2.6:5:41120) at Object.trigger (desktop_all.min.js?v=24.2.6:5:71782) at HTMLInputElement.<anonymous> (desktop_all.min.js?v=24.2.6:5:72378)
In this case, the column D does not get updated. But if we tried update A,B,C once again, we see that column D is updated and no other errors are raised. So after the error occurred once, the values are updated without any issue.
ISSUE 2:
We have also tried updating the value of A,B,C on existing rows upon entering the page, and we got this error:
Uncaught Error: Set calculated value not allowed for field
ie @ modelViewBase.min.js?v=24.2.6:4
setValue @ modelViewBase.min.js?v=24.2.6:4
_setModelValue @ modelViewBase.min.js?v=24.2.6:5
t.each.r.<computed> @ desktop_all.min.js?v=24.2.6:41
_deactivateCell @ widget.grid.min.js?v=24.2.6:4
t.each.r.<computed> @ desktop_all.min.js?v=24.2.6:41
(anonymous) @ widget.grid.min.js?v=24.2.6:4
setTimeout
_beginDeactivate @ widget.grid.min.js?v=24.2.6:4
t.each.r.<computed> @ desktop_all.min.js?v=24.2.6:41
focusout @ widget.grid.min.js?v=24.2.6:4
r @ desktop_all.min.js?v=24.2.6:41
dispatch @ desktop_all.min.js?v=24.2.6:5
v.handle @ desktop_all.min.js?v=24.2.6:5
trigger @ desktop_all.min.js?v=24.2.6:5
simulate @ desktop_all.min.js?v=24.2.6:5
n @ desktop_all.min.js?v=24.2.6:5Understand this error
In this case, the column D of the existing row will never get any update at all and the error will keep on being raised.
---
For this, the following code is used in the Column Initialization JavaScript Function in Advanced section of the column D in Interactive Grid:
function(options) {
options.defaultGridColumnOptions = {
dependsOn: ['A', 'B', 'C'],
calcValue: function(argsArray, model, record) {
if (!record || Object.keys(record).length === 0) {
return '';
}
const a = parseFloat(model.getValue(record, 'A') || 0);
const b = parseFloat(model.getValue(record, 'B') || 0);
const c = parseFloat(model.getValue(record, 'C') || 0);
let inputNum = 0;
try {
inputNum = parseFloat($v('P10_INPUT_NUM') || 1);
} catch (e) {
inputNum = 1;
}
if (isNaN(a) || isNaN(b) || isNaN(c) || isNaN(inputNum)) {
return '';
}
return (a - b - c) / inputNum;
}
};
return options;
}
What is the correct way to update the column D in this case? At the same time, we must not allow the user to update the value of column D directly as well.
Thank you