- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2020 03:10 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2020 03:30 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2020 03:19 AM
HI,
So what is happening now? If the UI action still visible even if it has the record?
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2020 03:32 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2020 03:30 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2020 03:32 AM
Cheers Ankur,
I just noticed the exact same mistake. Thanks for your quick response.
Thanks
Sam