g_form.submit() returns true or false in the Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 06:50 AM
Hi all,
I need clarifications on the GlideForm function subtmit() returns.
In the ServiceNow docs, the returns type is "void" but when I test "alert(g_form.submit())" it returns 'true' when a catalog item is submitted and 'false' when the submission is aborted. It sounds like the ServiceNow docs is wrong.
I want to use this because the customer ask to redirect to another page after the submission of a catalog request, the first try was like :
But we realized if the client forgot to fill mandatory fields, he is redirect to the page even though the submission is aborted because of the mandatory fields and the client loses the data he filled before he submits the form.
So we tried the code below, the if statement verifies if the the submission was accepted or not, if yes then we redrect else we do nothing
I am wondering if someone can confirm this solution. Is it steady ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 09:46 PM
Hi Hamza,
I would suggest that you use an OnSubmit catalog client script and then redirect the users, by doing that form will not be submitted without mandatory fields so there will be no data loss also user will not be redirected to any page.
You can make a condition check in OnSubmit if you want and then redirect the users accordingly.
For Example:
If(condition)
{
location.href = "?id=sc_cart";
}
If your are using this for portal as well then do make sure that you make Onsubmit script available to portal by selecting "All" in UI type field of client script.
Regards,
Lokesh Garg
P.S. : Please mark correct or helpful if appropriate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 12:51 AM
Thank you Lokesh.
The redirection must be set only for Portal.
Can we do it in Catalog Client Script without dom manipulation ?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2017 02:23 AM
Hi Hamza,
In catalog client script you can get the current URL parameters and based on that you can check whether it is portal or any other page and based on the condition check you can redirect using this script:
var id= getParmVal();
If(id){
location.href = "?id=sc_cart";}
function getParmVal(){
var url = document.URL
if(url.indexOf("sp")!=-1){
return true;
}
else{
return false;
}
}
I hope it helps and will solve your problem.
Regards,
Lokesh Garg
P.S. : Please mark correct or helpful if appropriate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2017 06:37 AM
Thanks Lokesh.
That would mean the Client Script will always be executed, which is not a good practice.
It seems the solution I described works fine, I'll keep you informed