how to validate group name of group table on catalog form when group name is given ,it should check if the group name already exists or not,if it gets it should get error message

sreelekha devar
Kilo Explorer

when group name is given,the field should check for its existing group names,if group name already exists,it should get error message

3 REPLIES 3

RAHUL YADAV9
Mega Guru
You can write a client callable script include where you will gliderecord the group table and pass group name as input parameter. Return if that names already exists or not. On catalog client script you can call the script include and on the basis of response show the desired error message. Please let me know if you need help in scripting. Please mark correct if this helps.

Geoff_T
Mega Sage

Hi,

An onChange client script on the catalog field where group name is entered:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var userGroups = new GlideAjax("UserGroups"); // script include name
    userGroups.addParam("sysparm_name", "doesGroupExist"); // script include function to call
    userGroups.addParam("sysparm_group", newValue); // value to pass to script include
    userGroups.getXML(callbackXML);

    function callbackXML(response) {
        // get the response
        var answer = response.responseXML.documentElement.getAttribute("answer");

        if (answer == "true") {
            alert("This Group Name already exists");
            g_form.setValue("groupname", "");
        }
    }
}

 

Then a script include (client callable):

find_real_file.png

 

var UserGroups = Class.create();
UserGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    // check if group exists
    doesGroupExist: function() {
		var groupName = this.getParameter("sysparm_group").toString();
		
        var groups = new GlideRecord('sys_user_group');
        groups.addQuery('name', groupName);
        groups.query();

        if (groups.next()) {
            return 'true';
        }
    },

    type: 'UserGroups'
});

 

Geoff

Hello @sreelekha devaraju 

Let me know if my provided solution worked for you and if so mark as correct to close the thread. Otherwise let me know if I can help further.

Thanks