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-17-2023 12:44 AM
@Ankur Bawiskar this field "u_eid"...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 12:50 AM
Is it because I used gliderecord thats why it doesnt get the the company code in the sys _user table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 12:54 AM
are you in scoped app? is this UI action created in custom scope?
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-17-2023 01:10 AM
Hi @Ankur Bawiskar yes the ui action button is created from scoped app. The reason also why we used a ui view is because we have a ui macro and the usage of this button is to show a printable form wherein the user can print the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 12:56 AM
why are you changing the view on UI action click?
You should use View rule if you want to show particular view to user based on some condition
Try this
I assume field u_companycd is on user table
function changeView(){
var EID = g_form.getValue('u_eid');
var id = g_form.getUniqueValue();
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", EID);
gr.query(checkRecord);
function checkRecord(gr){
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);
}
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader