Hi @hakyuz,
Thanks! Sure, happy to help with what I have. I also had the help of Ilia @ishapiro on this one at the time.
Ok, below are the details, for anyone interested.
The code was done in the file …\apq-c3-custom\js\custom-hook-functions.service.js
- First, add the Notifications to the Class for the custom hook functions:
- Create a function or use the same as existing “beforeCellUpdate” , the full code of the function, with some comments:
Note in this code I have a 2 dim cube that I first get the allowed amount ranges, to then do the checks for each input.
beforeCellUpdate(table, requests) {
/** CUSTOM FUNCTION ADDED TO CHECK CELL INPUT BASED ON A VALID NUMBER, WARN IF NOT ALLOWED! */
// this.$log.debug('beforeCellUpdate hook called', requests);
// return Promise.resolve({});
let currentRequestArrayIndexToRemove = [];
let allowed_val;
let allowed_val_min;
// Get allowed amounts from cube
return this.$tm1Ui.cellsetGet([{ instance: 'UX_Demo', cube: 'Sales Quota', cubeElements: ['Budget', 'Min Allowed'] }
, { instance: 'UX_Demo', cube: 'Sales Quota', cubeElements: ['Budget', 'Max Allowed'] }]).then((val) => {
allowed_val_min = val[0].Value
allowed_val = val[1].Value
console.log("VALUES ALLOWED: ", allowed_val_min, allowed_val);
/** Check each entry if value is between range, flag otherwise */
requests.forEach((request, index) => {
let currentVal = (request.value + '').split(',').join('')
// console.log("value: " + currentVal);
if (Number(currentVal) < allowed_val_min || Number(currentVal) > allowed_val) {
currentRequestArrayIndexToRemove.push(true)
} else {
currentRequestArrayIndexToRemove.push(false)
}
})
/** For each flagged "wrong" input, remove it from request of cube update, and do notification */
for (var i = currentRequestArrayIndexToRemove.length - 1; i >= 0; i--) {
if (currentRequestArrayIndexToRemove[i] === true) {
let input_val = requests[i].value;
//Remove value from request, so it does not update cube
requests.splice(i, 1);
this.Notifications.message("danger", "Input Validation", "Value '" + input_val + "' entered is Invalid, amount allowed is between " + allowed_val_min + " and " + allowed_val + "!", false)
}
}
if (requests.length === 0) {
this.$rootScope.$broadcast('updateTable', { "viewKey": table.key, tableId: table.tableId });
}
return Promise.resolve({ success: true });
});
}
-
At the end of the custom hook functions file, add the “Notifications” to the list so it can return to the app and the notification works.
-
Finally, in the UX report View or grid widget you want to do this check, add the function on the
BeforeCellUpdate functions:
after that, when entering a number, it will do this check and do a notification if the value is out of the allowed range. It will work with 1 single entry or multiple ones, like below:
Hope this helps! let me know you need any more details or would like to setup a call for a chat on this.