action setRedirect not working in scoped application

Armin Heinlein1
Giga Expert

I am trying to use UI Action ("Posts") to navigate to a new form within a scoped application but it doesn't work. It actually goes back to the list.

The var URL is properly populated because the list is displayed when I copy and paste it directly into a browser tab.

UI Action: Posts

Action name: add_posts

Show insert/update: true

Client: true

Form button: true

function getPosts() {

// save records

current.update();

// Prepare the URL for "Take me to the Information"

/* var instance = gs.getProperty("instance_name"); */

var instance = '<myinstance>';

var URL1 = 'https://' +instance;

var URL2 =
'.service-now.com/x_conym_gov_post_list.do?sysparm_first_row=1&sysparm_query=u_request%3D';

var request = g_form.getValue('u_request');

var URL3 = '&sysparm_view';

// Build final URL

var URL = URL1 +URL2 +request +URL3;

alert("URL = " +URL );

action.setRedirection(URL);

}

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

I totally missed the fact that you have client checked. You have (mostly) server side code in your script. Uncheck client and try this script instead. You cannot mix server side objects (like current and action) with client scripts in this manner.



// save records


current.update();


var URL1 = 'x_conym_gov_post_list.do?sysparm_first_row=1&sysparm_query=u_request%3D';


var request = current.getValue('u_request');


var URL2 = '&sysparm_view';


// Build final URL


var URL = URL1 +request +URL2;


gs.addInfoMessage(URL);


action.setRedirectURL(URL);


View solution in original post

7 REPLIES 7

If you MUST use client script and server script together, this article is very popular.



https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/


amlanpal
Kilo Sage

Hi Armin,



You might refer these 2 helpful threads addressing the same issue:


1. Redirect URL related List in scoped application


2. action.setRedirectURL not working



I hope this helps. Please mark correct/helpful based on impact


Ujjawal Vishnoi
Mega Sage
Mega Sage

Hi Armin,



I do not know why are you using client callable UI action. If you are really want to use client callable ui action then you will have the pass the control outsinde the function using gsftSubmit, once you are done with your client part and write the action.redirect outside of the function. Below is the syntax of using gsftSubmit.



gsftSubmit(null, g_form.getFormElement(), '<ui_action_name>');



and outside of the function you can use



if(typeof window == 'undefined')


{


action.setRedirectURL(URL);


}



If you find that you need not to use client callable then uncheck client and use below code.




current.update();


// Prepare the URL for "Take me to the Information"


var instance = gs.getProperty("instance_name");


var URL1 = 'https://' +instance;


var URL2 ='.service-now.com/x_conym_gov_post_list.do?sysparm_first_row=1&sysparm_query=u_request%3D';


var request = current.u_request;


var URL3 = '&sysparm_view';


// Build final URL


var URL = URL1 +URL2 +request +URL3;


action.setRedirection(URL);



Hope this helps.



Regards


Ujjawal