
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2017 05:44 PM
The business rule below should direct users to the selected catalog item to continue filling out the form. However, it is not redirecting instead it stays on the same page, any help would be much appreciated
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
var number = current.number;
var reqFor = current.requested_for;
var location = current.requested_for.location;
var reqBy = current.requested_by;
var reqItem = current.catalog_item;
var shortDescription = current.shortdescription;
var businessCase = shortDescription + '\n' + current.business_case+ '\n\n' + 'Created from Demand: '+number;
var comments = "DEMAND_REF:"+current.sys_id+" "+businessCase;
var deadline = current.u_deadline;
getCart();
var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=' + reqItem + '&sysparm_user=' + reqFor + '&sysparm_requested_by=' + reqBy + '&sysparm_deadline=' + GlideStringUtil.urlEncode(deadline) + '&sysparm_stnd_req_add_info=' + GlideStringUtil.urlEncode(businessCase) + '&sysparm_comments=' + comments;
action.setRedirectURL(url);
//Leave the ConnectUs record opened
var grCU = new GlideRecord('x_hemas_connectus2_x_hemas_connectus_connectus');
grCU.get(current.sys_id);
grCU.current_status = 'Service Request Opened';
grCU.update();
function getCart() {
var cart = new GlideRecord('sc_cart');
var userid = gs.getUserID();
cart.addQuery('user', userid);
cart.query();
if (cart.next()) {
// We already have a cart so override the requested for value and empty it
cart.requested_for = reqFor;
cart.special_instructions = comments;
cart.delivery_address = getDeliveryAddress();
cart.update();
var cartItems = new GlideRecord('sc_cart_item');
cartItems.addQuery('cart', cart.sys_id);
cartItems.deleteMultiple();
} else {
cart.initialize();
cart.user = userid;
cart.requested_for = reqFor;
cart.special_instructions = comments;
cart.delivery_address = getDeliveryAddress();
cart.insert();
}
return cart;
}
function getDeliveryAddress() {
var gr = new GlideRecord('cmn_location');
if (!gr.get(location))
return '';
var text = '';
if (!gr.street.nil())
text = gr.street + '\n';
if (!gr.city.nil() && !gr.state.nil() && !gr.zip.nil())
text += gr.city + ", " + gr.state + ", " + gr.zip;
return text;
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2017 03:20 PM
It's like Sachin says, action.setRedirectURL() is for UI Actions.Use gs.setRedirect() and it will work in after BR. https://developer.servicenow.com/app.do#!/api_doc?v=istanbul&id=r_ScopedGlideSystemSetRedirect_Objec...
//Göran

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2017 05:56 PM
Hi Edwin,
Can you please try this line of code action.setRedirectURL(url); after grU.update();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2017 06:18 PM
I did with no luck

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2017 06:28 PM
Please use gs.setRedirect in your business rule.
Below is sample code
- gs.setRedirect("com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=d41ce5bac611227a0167f4bf8109bf70&sysparm_user="
- + current.sys_id + "&sysparm_email=" + current.email)
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2017 01:38 PM
After doing some more debugging, I found the issue is with my business rule not getting triggered. I updated the rule to run before update vs after update and the rule ran yet when I changed it to after it did not run