
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2022 07:02 AM
Hello,
I have an UI action that is applied on both list and form. The button contains a script include and I have some calculations in it.
What I want to do is to redirect to current form when the UI action is clicked from form and of course, redirect to list when the UI action is clicked from the list.
I was thinking to add in my script something like:
if(clickedfromlist){ //no clue how to "call this"
var url=current.getTableName()+'_list.do';
action.setRedirectURL(url);
}else{
action.setRedirectURL(current);
}
If there any way to do it?
Thank you,
Elena
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2022 07:33 AM
Since you mentioned your UI action is server side; you can try to use this to detect if it's form or list
var tableName = 'incident'; // give your table name here
var isForm = gs.action.getGlideURI().toString().indexOf(tableName + '.do') > -1;
if(!isForm){
var url = current.getTableName()+'_list.do';
action.setRedirectURL(url);
}else{
action.setRedirectURL(current);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2022 07:33 AM
Since you mentioned your UI action is server side; you can try to use this to detect if it's form or list
var tableName = 'incident'; // give your table name here
var isForm = gs.action.getGlideURI().toString().indexOf(tableName + '.do') > -1;
if(!isForm){
var url = current.getTableName()+'_list.do';
action.setRedirectURL(url);
}else{
action.setRedirectURL(current);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2022 07:34 AM
Yeees, this is the check that I wanted to make but didn't know how to do it! Will try the code and let you know if it worked!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2022 07:47 AM
It works!!
Final code:
var tableName = current.getTableName();
var isForm = gs.action.getGlideURI().toString().indexOf(tableName + '.do') > -1;
if(!isForm){
var url = tableName +'_list.do';
action.setRedirectURL(url);
}else{
action.setRedirectURL(current);
}
Thank you and have a wonderful day,
Elena
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2022 08:18 AM
Glad to know !!
Happy learning and have a wonderful day ahead.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2022 01:28 AM
Hi,
I need to hide this UI action in related list. It needs to be shown only on form and in list.
Can I somehow specify this in the button condition like:
!(RP.isRelatedList()
Thanks,
Elena