On Portal form I want to give a soft block if any cases are open for selected requested for
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
When we are going submit the portal form the selected requested for user has any in progress case already exist. we should give a warning message when they did initial click on submit button(it will not allow to submit). Still he is ok to create new case again second time click on submit button( it will allow to submit the form).
How we can achieve ?
Note:- It should not be impact for no case existing users. if there is no in progress case we should allow to submit on single click on submit button.
Thanks in advance!,..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited 3 hours ago
Hi @MUDIGOLAM BHANU ,
Create an onSubmit Catalog Client Script that checks whether the requested user has any cases in progress by calling a Script Include using GlideAjax.
Add a hidden checkbox variable named "Acknowledge" to the catalog item.
Behavior:
When the user clicks Submit for the first time, call the Script Include to check if the requested user has any in-progress cases.
If a case exists and acknowledge check box is flase:
Display a warning message to the user.
Set the Acknowledge checkbox value to true.
Prevent the form submission.
3. if case not exist allow to submit
4.When the user clicks Submit again, run the same check.
Since the Acknowledge checkbox is already true, allow the form submission to proceed.
Sample code
function onSubmit() {
// Check if the validation has already run and passed
if (g_scratchpad.isFormValid) {
return true; // Allow form submission
}
// Stop the initial submission
var actionName = g_form.getActionName(); // Capture the submit action
// Call the asynchronous GlideAjax
var ga = new GlideAjax('YourScriptIncludeName'); // Replace with your Script Include name
ga.addParam('sysparm_name', 'yourFunctionName'); // Replace with your function name
// Add other parameters as needed
// ga.addParam('sysparm_variable_name', g_form.getValue('variable_name'));
// Define the callback function that will handle the response
ga.getXMLAnswer(function(answer) {
// Process the answer from the server
if (answer == 'true') { // Adjust condition based on your server response
g_scratchpad.isFormValid = true; // Mark validation as complete and successful
g_form.submit(actionName); // Programmatically re-submit the form
} else {
// Validation failed: display an error message and do not resubmit
g_form.showFieldMsg('your_field_name', 'Validation failed: ' + answer, 'error'); // Replace with appropriate message and field
g_scratchpad.isFormValid = false;
}
});
return false; // Crucial: Prevent the form from submitting immediately
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
is that a reference variable on form where users can be selected?
OR
You are referring to logged in user who is raising the request?
Ankur
⨠Certified Technical Architect || ⨠10x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi @NagaChandaE
Thanks for the response and code. let me try and get back to you.
Hello @Ankur Bawiskar ,
Reference from user table.
Req for field selected user is not logged in user.
Thanks,
Bhanu.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
remember these points:
1) Asynchronous GlideAjax won't work as by the time ajax function returns the value your form will get submitted
2) Synchronous GlideAjax is not allowed in portal and scoped application
Refer this link
Refer these links for workaround/solution on how to use Synchronous GlideAjax in onSubmit
How To: Async GlideAjax in an onSubmit script
Asynchronous onSubmit Catalog/Client Scripts in ServiceNow
š” If my response helped, please mark it as correct ā and close the thread šā this helps future readers find the solution faster! š
Ankur
⨠Certified Technical Architect || ⨠10x ServiceNow MVP || ⨠ServiceNow Community Leader

