UI Action Button Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 06:35 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 doesn't show anything , it doesn't work..
I'd appreciate any help. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 06:54 AM
UI action is on sys_user table
what's the business requirement here?
It seems based on field you are taking user to different view.
Why not use View Rules for this?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 07:00 AM
Hi @Ankur Bawiskar . The UI action is on our custom table.
From the custom table , we need to check if the employee company code is 0003. We need to get the employee EID in our custom table then check his/her company code in the sys_user table..
So, if his/her company code is 0003 then there will be a pop up url. otherwise, there will be a different pop up view for employees that are not part of 0003...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 07:29 AM
so your UI action is on custom table
Did you add alert and check script runs till what point?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 11:57 PM
Hi @Ankur Bawiskar . Yes I tried to put an alert after the if(gr.next()){. It doesnt give an alert. It seems like it doesnt find the sys id for the employee EID.
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()) {
alert('test');
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);
}
}}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 12:08 AM
which field on your custom table holds a reference to sys_user?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader