Need to pop up error message and restrict request submission of catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2023 10:42 PM
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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2023 10:49 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2023 10:52 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2023 11:01 PM
You have to define the script include with the below code and call it from the onSubmit catalog client script.