How to make attachments mandatory on SC Task based on variable condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 07:54 AM
I have a requirement to make attachment mandatory on SC Task Table if One of the variable value is Yes on a SC_TASK Table
I Have created a Before Business rule to make it mandatory , script is working fine , but i am not able to fetch the variable value with the below script
(function executeRule(current, previous /*null when async*/ ) {
var va = current.variable_pool.netstat_report;
current.addInfoMessage('Testing Catalog ' + va);
if (va == 'yes') {
var sctaskAttach = new GlideRecord('sys_attachment');
sctaskAttach.addQuery('table_sys_id', current.sys_id);
sctaskAttach.query();
if (!sctaskAttach.hasNext()) {
gs.addErrorMessage('Attachment is empty Please attach ');
current.setAbortAction(true);
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 08:08 AM
try this
var va = current.variables.netstat_report;
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 08:11 AM
Hi Ankur
I tried with both current.variables and variable_pool it is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 08:10 AM
Are you sure about below code line and getting the "addInfoMessage" message on screen.
Also, this "Yes/No" at variable section to at task level.
added return after "current.setAbortAction(true);" line.
(function executeRule(current, previous /*null when async*/ ) {
var va = current.variable_pool.netstat_report;
current.addInfoMessage('Testing Catalog ' + va);
if (va == 'yes') {
var sctaskAttach = new GlideRecord('sys_attachment');
sctaskAttach.addQuery('table_sys_id', current.sys_id);
sctaskAttach.query();
if (!sctaskAttach.hasNext()) {
gs.addErrorMessage('Attachment is empty Please attach ');
current.setAbortAction(true);
return false;
}
}
})(current, previous);
Please check and share the result. Also, put the correct "when to run" condition so this BR should run for dedicated SCTASKs belong to catalog item only.
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 08:23 AM
Hi Ashish
No this code is not getting addinfoMessage, i am not able to fetch the variable value with both variable_pool and variables
var va = current.variable_pool.netstat_report;
var va = current.variables.netstat_report;