action.setRedirectURL not working

rlegters
Mega Expert

I'm trying to open a wizard from a UI Action, and it's not working. From what I've read on the wiki, it looks like I should be using action.setRedirectURL with the url as the url of the wizard:

function new_request_message() {

    alert('clicked');

action.setRedirectURL('expert_shell.do?sysparm_sys_id=4f0a1b3538f695002ae704ffa136f274&sysparm_initial=true&sysparm_view=wizard');

alert('done');

}

I've added the alerts just for debugging. If I comment out the action.setRedirectURL line, I get both alerts. With that uncommented, I only get the first. In either case, I don't get a new window or anything at all opening up when I click the button. I copied the syntax from the 'Test' UI action on the 'expert' table, but I'm clearly missing something.

 

Any help?

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

action.setRedirectURL() is a server side function, but alert() is a client side function, so if alert() is working you're probably running the ui action client side. In that case you can just use the standard window.location to redirect to the wizard.



function new_request_message() {


    alert('clicked');


    window.location = 'expert_shell.do?sysparm_sys_id=4f0a1b3538f695002ae704ffa136f274&sysparm_initial=true&sysparm_view=wizard';


    alert('done');


}



You could also convert this to a server side ui action to use action.setRedirectURL().


View solution in original post

3 REPLIES 3

Brad Tilton
ServiceNow Employee
ServiceNow Employee

action.setRedirectURL() is a server side function, but alert() is a client side function, so if alert() is working you're probably running the ui action client side. In that case you can just use the standard window.location to redirect to the wizard.



function new_request_message() {


    alert('clicked');


    window.location = 'expert_shell.do?sysparm_sys_id=4f0a1b3538f695002ae704ffa136f274&sysparm_initial=true&sysparm_view=wizard';


    alert('done');


}



You could also convert this to a server side ui action to use action.setRedirectURL().


Thanks! That worked.



Thanks,


Ron Legters


System Administrator


Univar


T +1 425 889 3952


smruti
Kilo Contributor

Hello brad,

I have tried using window.location but it is giving error as "Server Javascript error 'window' is not defined".

Kindly suggest alternatives.

Thanks,

Smruti