Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

how to restrict the standard change creation when assignment group is inactive

RamcharanA
Tera Contributor

How to prevent standard change creation when assignment group is inactive.

1 ACCEPTED SOLUTION

Hello @RamcharanA, I'm not sure why you'd like to go for this approach when there are better approaches, highlighted earlier, available. Nevertheless, here are the SI and CS as asked:

- Script Include: ensure its client callable as depicted below

Nishant8_0-1748502826861.png

Here is the script to be used in SI

var TestRestrictChangeInactiveAssignedGroup = Class.create();
TestRestrictChangeInactiveAssignedGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	inactiveGroupCheck: function(){
		var assignedGroup = this.getParameter('sysparm_assignedGroup');
		var grGroup = new GlideRecord('sys_user_group');
		grGroup.get(assignedGroup);
		grGroup.addActiveQuery();
		grGroup.query();
		return grGroup.hasNext();
	},
    type: 'TestRestrictChangeInactiveAssignedGroup'
});

 - Client Script: its configured to run only for new record, if you wish to run it for existing Change too then remove the first if condition

Nishant8_1-1748503016442.png

Here is the script to be used

function onSubmit() {
	//Runs only for new record
    if (g_form.isNewRecord()) { // remove if condition here if to be run for update too
        var gaAssignedGroup = new GlideAjax('TestRestrictChangeInactiveAssignedGroup');
        gaAssignedGroup.addParam('sysparm_name', 'inactiveGroupCheck');
        gaAssignedGroup.addParam('sysparm_assignedGroup', g_form.getValue('assignment_group'));
        gaAssignedGroup.getXMLWait(); // doesn't work in portal
        var isActiveGroup = gaAssignedGroup.getAnswer();
        if (isActiveGroup === 'false') {
            g_form.addErrorMessage('Selected Group is inactive');
            return false;
        }
    }
}

 

Regards,

Nishant

View solution in original post

5 REPLIES 5

Hello @RamcharanA, I'm not sure why you'd like to go for this approach when there are better approaches, highlighted earlier, available. Nevertheless, here are the SI and CS as asked:

- Script Include: ensure its client callable as depicted below

Nishant8_0-1748502826861.png

Here is the script to be used in SI

var TestRestrictChangeInactiveAssignedGroup = Class.create();
TestRestrictChangeInactiveAssignedGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	inactiveGroupCheck: function(){
		var assignedGroup = this.getParameter('sysparm_assignedGroup');
		var grGroup = new GlideRecord('sys_user_group');
		grGroup.get(assignedGroup);
		grGroup.addActiveQuery();
		grGroup.query();
		return grGroup.hasNext();
	},
    type: 'TestRestrictChangeInactiveAssignedGroup'
});

 - Client Script: its configured to run only for new record, if you wish to run it for existing Change too then remove the first if condition

Nishant8_1-1748503016442.png

Here is the script to be used

function onSubmit() {
	//Runs only for new record
    if (g_form.isNewRecord()) { // remove if condition here if to be run for update too
        var gaAssignedGroup = new GlideAjax('TestRestrictChangeInactiveAssignedGroup');
        gaAssignedGroup.addParam('sysparm_name', 'inactiveGroupCheck');
        gaAssignedGroup.addParam('sysparm_assignedGroup', g_form.getValue('assignment_group'));
        gaAssignedGroup.getXMLWait(); // doesn't work in portal
        var isActiveGroup = gaAssignedGroup.getAnswer();
        if (isActiveGroup === 'false') {
            g_form.addErrorMessage('Selected Group is inactive');
            return false;
        }
    }
}

 

Regards,

Nishant