How to make attachments mandatory on SC_TASK

VickyRai1
Tera Contributor

Hello all,

 

I have a requirement for making attachment mandatory on sc_task, but i have multiple catalog task and i want to make attachment mandatory on a particular task. please let me know how we can achieve it.

 

Thanks in Advance

1 ACCEPTED SOLUTION

Shubham Pal
Tera Expert

Hello VickyRai1,

 

Please use the below code in Business Rule 

 

(function executeRule(current, previous /*null when async*/) {

// gs.addInfoMessage("Result:"+current.hasAttachments());

if(current.hasAttachments() != true){

gs.addInfoMessage("Please add an attachment");

current.setAbortAction(true);

}}

)(current, previous);

 

And set When to run as before , update.

use condition as requested item.item is "catalog item name".

and state changes to closed complete.

View solution in original post

5 REPLIES 5

chetanb
Tera Guru

Can you please elaborate you requirement on what criteria you want attachment should be mandatory on sctask.

 

Regards,

CB

Hi chetanb,

According to the variables on my form i have multiple tasks and on a particular variable i want attachments to be mandatory. 

PFA as the reference, the highlighted field creates a separate task for it and i want that task to have mandatory attachments.

swathisarang98
Giga Sage
Giga Sage

Hi @VickyRai1,

 

You can create before update Business rule on sc_task table with the below script, please mention the condition if required,

 

 

 

(function executeRule(current, previous /*null when async*/) {


  var att = new GlideAggregate('sys_attachment');
  att.addAggregate('COUNT');
  att.addQuery('table_name', current.getTableName());
  att.addQuery('table_sys_id', current.sys_id);
  att.query();
  var count = 0;


  if (att.next()) {
  count = att.getAggregate('COUNT');
  if (count<1) {
  gs.addInfoMessage("Attachment is Mandatory");
  current.setAbortAction(true);
  }
  }

})(current, previous);

 

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

Shubham Pal
Tera Expert

Hello VickyRai1,

 

Please use the below code in Business Rule 

 

(function executeRule(current, previous /*null when async*/) {

// gs.addInfoMessage("Result:"+current.hasAttachments());

if(current.hasAttachments() != true){

gs.addInfoMessage("Please add an attachment");

current.setAbortAction(true);

}}

)(current, previous);

 

And set When to run as before , update.

use condition as requested item.item is "catalog item name".

and state changes to closed complete.