On Cell edit query

Community Alums
Not applicable

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:

JPRamyaPriya_0-1690137449392.png

 

Script include:

JPRamyaPriya_1-1690137509813.png

 

How to pass newValue of subcategory to script include?

Any help is appreciate!!

Thanks in advance!!

 

 

2 ACCEPTED SOLUTIONS

Riya Verma
Kilo Sage
Kilo Sage

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:

  1. the "When to run" section, select "Before" to ensure the rule runs before the record is submitted.
  2. 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.

 

 

 

 

 
 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

View solution in original post

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.

View solution in original post

10 REPLIES 10

Community Alums
Not applicable

Thanks for the script, however we choosed BR over OnCEllEdit client script.