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:42 AM
Hi Dizy,
Did you try window.open()? If not, please modify you code as below and try.
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";
window.open(url, '_blank');
}
else{
var url2 = table + ".do?sys_id=" + id + "&sysparm_view=SUPERVISORVIEW";
window.open(url2, '_blank');
}
}}
If my answer helps then please mark it Helpful or Correct!
Thanks,
Utpal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 06:45 AM
Also please check if you have entered the function name in the onClick field of the UI action form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 06:52 AM - edited 10-16-2023 06:53 AM
Hi @Utpal Dutta Thank you for your reply!
The "g_navigation.openPopup" seems working fine..
Because when I try the code below, it shows the url, it works . However when I tried to query the sys user table and tried to get if the employee company code is 0003, it doesnt pop up the link...
function changeView(){
try{
var table = g_form.getTableName();
var id = g_form.getUniqueValue();
var url = table + ".do?sys_id=" + id + "&sysparm_view=EMPLOYEEVIEW";
g_navigation.openPopup(url);
}
catch(err){
console.log(err);
}}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 06:52 AM
are you sure your UI action is configured correctly to run the function?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader