- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2023 11:40 AM
Hi All,
From incident list, if the category changes to software and subcategory changes to email then record should not submit.
I have written the On cell edit client script:
Script include:
How to pass newValue of subcategory to script include?
Any help is appreciate!!
Thanks in advance!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 05:26 AM - edited 07-24-2023 05:29 AM
Hi @Community Alums ,
Hope you are doing great.
Its not a good practice to use on cell edit client script , for your requirement , you can go ahead with before BR:
- the "When to run" section, select "Before" to ensure the rule runs before the record is submitted.
- For the "Advanced" condition, use the following script:
(function executeRule(current, previous /*, g*/) {
if (current.category.changes() || current.subcategory.changes()) {
if (current.category == 'software' && current.subcategory == 'email') {
current.setAbortAction(true);
gs.addErrorMessage("Record submission is not allowed when the category is 'software' and the subcategory is 'email'.");
}
}
})(current, previous);
Also when you are using getXML call while calling script include via GlideAjax, its a asynchronous call so it will be going into queue. it will not going to wait to get the response from server and decide the abort action. So this is reason why its failing in script. Try using before BR for your requirement to abort submit.
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 07:16 AM
Hi @Community Alums ,
You have a solution now using onCellEdit from Khasim Pathan. I also tried, my version follows
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
//Type appropriate comment here, and begin script below
var sysIDstr = sysIDs;
// alert('sysIDstr = ' + sysIDstr + ', newValue = ' + newValue);
if (newValue == 'email') {
var incGA = new GlideAjax('incidentTable');
incGA.addParam('sysparm_name', 'tablequery');
/* These don't work for some reason
incGA.addParam('sysparm_syssid', sysIDstr);
incGA.addParam('sysparm_newvalues', newValue);
*/
incGA.addParam('sysparm_newValue', newValue);
incGA.addParam('sysparm_sysId', sysIDstr);
incGA.getXML(myid);
}
function myid(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var res = JSON.parse(answer);
if (res.status === 'false') {
alert(res.message);
callback(false);
}
else
callback(true);
}
}
Script include:
var incidentTable = Class.create();
incidentTable.prototype = Object.extendsObject(AbstractAjaxProcessor, {
tablequery: function() {
obj = {};
obj.status = 'true';
obj.message = '';
var newValue = this.getParameter('sysparm_newValue');
var sysId = this.getParameter('sysparm_sysId');
// gs.info("incidentTable: newValue = " + newValue + ", sysId = " + sysId);
/* doesn't work
var incID = this.getParameter('sysparam_syssid');
var incSC = this.getParameter('sysparam_newvalues');
gs.info('incidentTable: Checking for sys_id = ' + incID + ', incSC = ' + incSC + '.');
*/
var incCategory = '';
var empname = new GlideRecord('incident');
empname.addQuery('sys_id', sysId);
empname.query();
// gs.info('incidentTable: Found ' + empname.getRowCount() + ' records.');
if (empname.next()) {
// gs.info('incidentTable: category: ' + empname.category);
incCategory = empname.category;
}
if ((incCategory == 'software') && (newValue = 'email')) {
// gs.info('incidentTable: Got invalid combination.');
obj.status = 'false';
obj.message = gs.getMessage('Invalid combination of Category: software and Subcategory: email');
return JSON.stringify(obj);
}
return JSON.stringify(obj);
},
type: 'incidentTable'
});
I changed some name values, as starting with your versions didn't work. Also see examples of how to debug the client script and script include (Debug lines have been commented out). And from what I can tell, this only works in List view of incident. As I can still select that combination on the incident form. A business rule solution would prevent both. But you can satisfy your lead with the above or what Khasim posted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2023 08:13 AM
Thanks for the script, however we choosed BR over OnCEllEdit client script.