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

Chandu Telu
Tera Guru
Tera Guru

Hi 

Check the below link

https://community.servicenow.com/community?id=community_question&sys_id=ec1d8b69db9cdbc01dcaf3231f961933

 

Thanks
Chandu Telu
Please Mark Correct/helpful, if applicable,

Hello, 

 

Thank you for your answer! I checked the link and it isn't exactly what I need. My code in the UI action is server side.

 

Thank you,

Elena

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can determine the URL and know if it's form or list in client side

Is your UI action purely server side?

Regards
Ankur

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

Hi Ankur,

 

My code is purely server side.

It worked good for the form but I have a new requirement that needs to calculate "delta" for more records in a list.

I can create a similar UI action for list, that has a different redirect but I thought there is another solution to utilize the existing one.

Here is the code:

var addendumSysId = current.sys_id.toString();
var addendumChangeDate = current.u_change_date;
var addendumValEndDate = current.u_price_validity_end_date;

new AddendumTotalValue().calculateDelta(addendumSysId, addendumChangeDate, addendumValEndDate);

action.setRedirectURL(current);

 

What do you think is the best practice?

 

Thank you,

Elena