How to make attachments mandatory on SC Task based on variable condition

rakshith_shetty
Tera Contributor

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);

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@rakshith_shetty 

try this

var va = current.variables.netstat_report;

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

Hi Ankur

 

I tried with both current.variables and variable_pool  it is not working

AshishKM
Kilo Patron
Kilo Patron

Hi @rakshith_shetty 

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

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;