Script To Redirect if Matches Found
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2023 09:18 AM
Currently on a record producer I want to check if there are already open orders being worked on. If so I want to stop submission and take them to the list. I have the redirect working but if they click NO it creates the record and if there are no matches it stops them from submitting. Having trouble figuring out how if matches STOP and offer to take them to the list of matches instead or not allow submit. If no matches business as usual. Here is the script Im using so far.
function onSubmit() {
//Type appropriate comment here, and begin script below
var orderID = g_form.getValue("u_order_number");
var orderResult = new GlideRecord("u_flooring_measures");
orderResult.addQuery("active", true);
orderResult.addQuery("u_order_number", orderID);
orderResult.query();
if (orderResult.next()) {
if (confirm("There is already a open Measure Request for this order, Would you like to view it?")) {
//var resultID = orderResult.sys_id.toString();
var editURL = "https://instance.service-now.com/u_flooring_measures_list.do?sysparm_query=active%3Dtrue%5Eu_order_number%3D" + orderID + "%5EORu_original_order%3D" + orderID + "&sysparm_view=";
top.window.location = editURL;
}
} else {
alert("Your Measure has not been submitted.");
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2023 09:39 AM
@Nic Omaha , I dont see any logic applied if user clicks on NO,the else block is using when there are no active records match and in that case it's returning false. so you need this else condition along with the 2nd if condition where you are checking for confirmation.
For the 1st if condition, in else just use,
else{
return true;}
Your script should be like the below one.
if (orderResult.next()) {
if (confirm("There is already a open Measure Request for this order, Would you like to view it?")) {
//var resultID = orderResult.sys_id.toString();
var editURL = "https://instance.service-now.com/u_flooring_measures_list.do?sysparm_query=active%3Dtrue%5Eu_order_number%3D" + orderID + "%5EORu_original_order%3D" + orderID + "&sysparm_view=";
top.window.location = editURL;
}
else {
alert("Your Measure has not been submitted.");
return false;
}
} else {return true;}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2023 09:41 AM
Hi
Can you try below script-
function onSubmit() {
//Type appropriate comment here, and begin script below
var orderID = g_form.getValue("u_order_number");
var orderResult = new GlideRecord("u_flooring_measures");
orderResult.addQuery("active", true);
orderResult.addQuery("u_order_number", orderID);
orderResult.query();
if (orderResult.next()) {
if (confirm("There is already a open Measure Request for this order, Would you like to view it?")) {
//var resultID = orderResult.sys_id.toString();
var editURL = "https://instance.service-now.com/u_flooring_measures_list.do?sysparm_query=active%3Dtrue%5Eu_order_number%3D" + orderID + "%5EORu_original_order%3D" + orderID + "&sysparm_view=";
top.window.location = editURL;
} else {
alert("You did not confirm the popup");
return false;
}
} else {
alert("Your Measure has not been submitted.");
return false;
}
}
Thanks and Regards,
Saurabh Gupta