UI action for list and form

Elena Pomana
Tera Guru

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

1 ACCEPTED SOLUTION

@Elena Pomana 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

@Elena Pomana 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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!

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

@Elena Pomana 

Glad to know !!

Happy learning and have a wonderful day ahead.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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