The CreatorCon Call for Content is officially open! Get started here.

UI Action to Redirect to a URL

nagaraju8
Kilo Guru

Hi All,

I have a requirement, based on user subregion ess portal page will appear i.e when we click on a UI button first it check the user subregion and redirects to that specific ESS portal page. How to do it please any one help me.

Regards,

Nagaraju    

1 ACCEPTED SOLUTION

ghsrikanth
Tera Guru

From UI Action, you can always query server side GlideRecord script -



var userId = gs.getUserID();



var grUser = new GlideRecord('sys_user');


if(grUser.get(userId)){


var userRegion = grUser.region;


//you can use userRegion here


}



An example UI action with gliderecord query in out of box -


https://instancename.service-now.com/nav_to.do?uri=sys_ui_action.do?sys_id=399b3492d701310013ab49547...



Mark if it is helpful or correct, feedback is appreciated


View solution in original post

8 REPLIES 8

ghsrikanth
Tera Guru

In the UI Action, you can access the User's subregion by quering the sys_user table using gs.getUserID();


And can redirect to any url with the below line -


action.setRedirectURL('http://www.mysite.com/mypage.htm');



Hopefully you have explored this option -


UI Actions - ServiceNow Wiki


Hi srikanth,


Thanks for your information.


I got the user id, but how I get user subregion.



Regards,


Nagaraju


Nagaruaju,



Gliderecord the sys_user table with the sys_id of the current user logged in. From there you can retrieve the subregion value


sample of the script :


var currentUser = gs.getUserID()


var subRegion = '';


var subR = GlideRecord('sys_user');


subR.addQuery(sys_id'', currentUser );


subR.query();


if (subR.next()) {


        subRegion   = subR.u_subregion;


}


if (subRegion == 'servicenowLand') {


        action.setRedirectURL('www.www.ww');


} else {


        action.setRedirectURL('www.xxx.xx');


}


Hi ZA,


It is working fine for me.Thanks a lot for your information.



Regards,


Nagaraju