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

Chuck Tomasi
Tera Patron

The syntax is:



action.setRedirectURL(url)



or



action.setRedirectURL(GlideRecord object); // example. current)


SanjivMeher
Kilo Patron
Kilo Patron

Hi Armin,



Try below script



function getPosts() {


// save records


current.update();


var x = new GlideRecord('x_conym_gov_post_list');


x.addQuery('u_request',current.u_request);


x.query();


if (x.next())


        action.setRedirection(x);


}



Please mark this response as correct or helpful if it assisted you with your question.

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);


Hi Chuck,



That did the trick. Thank you.



Armin