Business Rule not redirecting to service catalog item form

Edwin Fuller
Tera Guru

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;

}

}

1 ACCEPTED SOLUTION

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


View solution in original post

5 REPLIES 5

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