Redirect in business rule not working

MC1
Tera Contributor

I have an onAfter business rule that runs on updates. Literally all I'm trying to do is have it redirect to the instance homepage. I've already logged the URL and confirmed that it's correct but it's not working. Here is my code:

(function executeRule(current, previous /*null when async*/) {
	var baseUrl = gs.getProperty('glide.servlet.uri');
	gs.setRedirect(baseUrl);
})(current, previous);


I have also tried using action.setRedirectUrl(baseUrl) and well as current.setRedirect(baseUrl). None of these work. Even if handling the redirect in a UI Action could work, I need this to be done in a business rule.

3 REPLIES 3

jMarshal
Mega Sage
Mega Sage

I'm guessing the problem is that it is onAfter...it doesn't trigger until after the crud operation at which time there is no redirect, the redirect/page load is done.

Test the theory with onBefore and see if that helps? If the rest of your BR needs to be onAfter, perhaps separate the tasks/steps into different BRs...?

MC1
Tera Contributor

I have tried making it onBefore as well.

Sagar Pagar
Tera Patron

Hi @MC1,

 

Have you tried the below one?

 

action.setRedirectURL(url);

 

Else take a look at old thread: Business rule action.SetRedirectURL(url); or gs.setRedirect(url); not working for me 

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar

The world works with ServiceNow