- 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
07-23-2023 09:33 PM
Hi, what are the results of your debugging\testing? what exactly is\is not working?
Evaluating screenshots is not ideal, perhaps you could share your code as plain text.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 01:03 AM
Thanks Tony!!
what are the results of your debugging\testing? -- In the alert we are getting old value of category
what exactly is\is not working? - if we change category to software in the list and sub category changes to email then record should not submit to server. Script should check is it category is software or not, if yes, then the record should abort.
On cell edit Client script:
Field name: Sub category
Script:
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('incidenttTable');
ga.addParam('sysparm_name', 'tablequery');
ga.addParam('sysparm_syssid', sysIDs);
ga.addParam('sysparm_newvalues', newValue);
ga.getXML(myid);
function myid(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('ramya' + answer);
if (answer == 't1')
if (newValue == 'email')
alert('anns' + answer);
saveAndClose = false;
}
callback(saveAndClose);
}
Script Include:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 05:09 AM
Hi @Community Alums ,
You can acheive this without coding.
1. Create Before Insert/Update BR.(It'll work for list editing too)
2. Filter conditions : category is software
Subcategory is Email
3. Under actions Tab: select Add message & Abort action.
Note: Script includes + OncellEdit scripts are not efficeint together , You can user before BR.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 06:32 AM
Hi Khasim,
Thanks!!
My lead want me to do with On cell Edit.
Any idea?