attachment mandatory on sc_task table

tGhadage
Tera Contributor

Hi Guys , 

 

I have requirement where if there is no attachment on the 'sc_task' use it should not be able to move state to close complete.

I have written a business rule for that: 

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

    // Add your code here
   var attachment_file = new GlideRecord('sys_attachment');
   attachment_file.addQuery('sys_id',gs.userID);
   attachment_file.query();
   
   if(attachment_file != true){
   gs.addErrorMessage('Please attach the Laptop/Desktop retrival checklist before closing the task');
   current.state=previous.state;
   current.setAbortAction(true);
}
})(current, previous); 
 
can you please tell what's wrong in it. 
thanks!!

 

2 ACCEPTED SOLUTIONS

Bhavya11
Kilo Patron

HI @tGhadage  

 

Please use this script because this query is wrong attachment_file.addQuery('sys_id',gs.userID);

 

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

	var attachment_file = new GlideRecord('sys_attachment');

// Query for attachments related to the current record
attachment_file.addQuery('table_sys_id', current.sys_id); // Query based on the current record's sys_id
attachment_file.query();
if (!attachment_file.hasNext()) {
    gs.addErrorMessage('Please attach the Laptop/Desktop retrieval checklist before closing the task');
    current.state = previous.state; // Revert state if no attachments are found
    current.setAbortAction(true); // Prevent closing the task
}

})(current, previous);

 

 If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."

 

 

Thanks,

BK

View solution in original post

Krushna R Birla
Kilo Sage

Hi @tGhadage  

 

Use below script to resolve your issue,

 

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

    var attachment_file = new GlideRecord('sys_attachment');
    attachment_file.addQuery('table_sys_id', current.sys_id);
    attachment_file.query();
    if (!attachment_file) {
        current.state = previous.state;
        gs.addErrorMessage('Please attach the Laptop/Desktop retrival checklist before closing the task');
        current.setAbortAction(true);
    }

})(current, previous); 

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Best Regards,
Krushna Birla

View solution in original post

3 REPLIES 3

Bhavya11
Kilo Patron

HI @tGhadage  

 

Please use this script because this query is wrong attachment_file.addQuery('sys_id',gs.userID);

 

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

	var attachment_file = new GlideRecord('sys_attachment');

// Query for attachments related to the current record
attachment_file.addQuery('table_sys_id', current.sys_id); // Query based on the current record's sys_id
attachment_file.query();
if (!attachment_file.hasNext()) {
    gs.addErrorMessage('Please attach the Laptop/Desktop retrieval checklist before closing the task');
    current.state = previous.state; // Revert state if no attachments are found
    current.setAbortAction(true); // Prevent closing the task
}

})(current, previous);

 

 If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."

 

 

Thanks,

BK

Krushna R Birla
Kilo Sage

Hi @tGhadage  

 

Use below script to resolve your issue,

 

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

    var attachment_file = new GlideRecord('sys_attachment');
    attachment_file.addQuery('table_sys_id', current.sys_id);
    attachment_file.query();
    if (!attachment_file) {
        current.state = previous.state;
        gs.addErrorMessage('Please attach the Laptop/Desktop retrival checklist before closing the task');
        current.setAbortAction(true);
    }

})(current, previous); 

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Best Regards,
Krushna Birla

hi , 

have used our updated script but still its not working. 

here is the script :

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

    // Add your code here
   var attachment_file = new GlideRecord('sys_attachment');
   attachment_file.addQuery('table_sys_id',current.sys_id);
   attachment_file.query();
   
   if(attachment_file != 'true'){
   gs.addErrorMessage('Please attach the requried documents before closing the task');
   current.state=previous.state;
   current.setAbortAction(true);
}
})(current, previous);
task is not getting close complete even when I have attached the attachment.