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

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

So what is happening now? If the UI action still visible even if it has the record?


Thanks,
Ashutosh

Hi Ashutosh,

Apologies I should have put that initially.  Yes the UI Action was still displaying when the m2m related list had a record.  I think I have managed to fix the issue.  I was missing 'new' before my call to the script include in the condition.  I've updated it to the following and it seems to now be working:

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

Thanks

Sam

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

Cheers Ankur,

I just noticed the exact same mistake.  Thanks for your quick response.

Thanks

Sam