Need to pop up error message and restrict request submission of catalog item

chiranjeevi Kup
Tera Expert

I have catalog item with two variables called Group (reference) and the Group member (List collector Variable Type) now I want to restrict the request submission if the selected group has only one member when am trying to remove member from the group in it and need to pop-up error message saying group cannot be empty,

 

Kindly help me with the approach, Thanks in advance !

3 REPLIES 3

Amit Gujarathi
Giga Sage
Giga Sage

HI @chiranjeevi Kup ,
I trust you are doing great.
please find the below code for the same.

function onSubmit() {
    var groupId = g_form.getValue('group'); // Replace 'group' with the actual variable name
    var gr = new GlideRecord('sys_user_grmember'); // Replace 'sys_user_grmember' with the actual group member table name
    gr.addQuery('group', groupId);
    gr.query();

    var memberCount = 0;
    while(gr.next()) {
        memberCount++;
    }

    if (memberCount <= 1) {
        var errorMessage = "Group cannot be empty. Please add more members to the group.";
        g_form.addErrorMessage(errorMessage);
        return false; // Prevents form submission
    }

    return true; // Allows form submission
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Anand Kumar P
Giga Patron
Giga Patron

Hi @chiranjeevi Kup ,

You have to write onSubmit catalog client script and use

function onSubmit() {
    var groupId = g_form.getValue('group'); // Replace 'group' name
    var groupMembers = g_form.getValue('group_member'); // Replace 'group_member' name
    if (groupId && groupMembers && groupMembers.length === 1) {
        alert("The selected group must have more than one member.");
        return false; 
    }
    return true;
}

Please mark it as helpful and solution proposed if it serves your purpose.

Thanks,

Anand

Vasu ch
Kilo Sage

Hi @chiranjeevi Kup 

You have to define the script include with the below code and call it from the onSubmit catalog client script.

 

Vasuch_0-1700550089433.png