- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2023 04:50 AM
Hi!
I'd like to ask if anyone here has an idea what went wrong withthis code?
This is our UI Action button script.
The requirement is if the employee company code is "0003", it will open a pop up url and if the employee code is not "0003" it will open a different pop up url.
function changeView(){
var EID = g_form.getValue('u_eid');
var table = g_form.getTableName();
var id = g_form.getUniqueValue();
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", EID);
gr.query();
if (gr.next()) {
if (gr.u_companycd == '0003') {
var url = table + ".do?sys_id=" + id + "&sysparm_view=EMPLOYEEVIEW";
g_navigation.openPopup(url);
}
else{
var url2 = table + ".do?sys_id=" + id + "&sysparm_view=SUPERVISORVIEW";
g_navigation.openPopup(url2);
}
}}
But what happened was whenever I click the UI Action button, it doesnt show anything , it doesnt work..
I'd appreciate any help. Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2023 07:42 AM
Hi,
Uncheck client checkbox on ui action and try below code
function changeView() {
var EID = current.u_eid;
var table = current.getTableName();
var id = current.sys_id;
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", EID);
gr.query();
if (gr.next()) {
if (gr.u_companycd == '0003') {
var url = '/' + table + '.do?sysparm_stack=' + table + '.do&sys_id=' + id + '&sysparm_view=EMPLOYEEVIEW';
action.setRedirectURL(url);
} else {
var url2 = '/' + table + '.do?sysparm_stack=' + table + '.do&sys_id=' + id + '&sysparm_view=SUPERVISORVIEW';
action.setRedirectURL(url2);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2023 05:05 AM
Hi,
Instead of GlideRecord.. pls use GlideAjax
Since GlideRecord is not recommended in client side scripts. Best practice is to use GlideAjax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2023 05:07 AM
Try below:
1. g_navigation.open(url)
OR
2. top.window.location =url ;
Please mark the answer correct/helpful accordingly.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2023 07:42 AM
Hi,
Uncheck client checkbox on ui action and try below code
function changeView() {
var EID = current.u_eid;
var table = current.getTableName();
var id = current.sys_id;
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", EID);
gr.query();
if (gr.next()) {
if (gr.u_companycd == '0003') {
var url = '/' + table + '.do?sysparm_stack=' + table + '.do&sys_id=' + id + '&sysparm_view=EMPLOYEEVIEW';
action.setRedirectURL(url);
} else {
var url2 = '/' + table + '.do?sysparm_stack=' + table + '.do&sys_id=' + id + '&sysparm_view=SUPERVISORVIEW';
action.setRedirectURL(url2);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2023 07:47 PM
Hi @Shruti . Thank you for this! The result is when I click the button, it seems like it just refresh the page and not go to the url.