UI Action on form to only show wen related list is empty

Sam Ogden
Tera Guru

Hi all,

I've got a custom UI action on the sc_task table.  I want to include a condition to only make this action display when there is no record matching in a related m2m list.

I've created this function in a script include called 'CdlStandardChange' :

linkedToChng : function(sctask){
		var link = new GlideRecord('u_m2m_catalog_task_change_reque');
		link.addQuery('u_catalog_task', sctask);
		link.query();
		if(link.next()){
			return true;
		} else {
			return false;
		}
	},

I have my condition in the UI Action as:

current.request_item.cat_item == '38190489dbd13240ddb9338ffe9619ed' && !CDLStandardChange().linkedToChng(current.sys_id)

The UI Action is called 'Add to Standard Change' and I only want it to display when there is not change linked to the sctask in the 'u_m2m_catalog_task_change_reque' related list.

The UI action adds a record to this related list, so esentially once the button has been clicked once I want it to no longer display to prevent duplicate entries into the m2m table.

I will then want a different UI Action to appear when a record does exist in the m2m and not display when there is not a record (the opposite logic)

Thanks

Sam

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@samogden 

you missed the new operator for the script include call in the UI action condition;

please update as below and test once

!new CDLStandardChange().linkedToChng(current.sys_id)

For making it work in opposite use this

current.request_item.cat_item == '38190489dbd13240ddb9338ffe9619ed' && new CDLStandardChange().linkedToChng(current.sys_id)

Regards
Ankur

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

View solution in original post

5 REPLIES 5

@samogden 

Glad to know.

if you think there is any response that helps you please mark that helpful or accepted so that this thread can be closed.

Regards
Ankur

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