The CreatorCon Call for Content is officially open! Get started here.

CTASK Attachment mandatory

MK21
Tera Contributor

Hi all,

 

I created the below script for Change task for Attachment Mandatory and but

IN THE emergency change short descrption is impementation task , in code i wrote implementation 

 

(function executeRule(current, previous /*null when async*/ ) {
var chg = new GlideRecord("change_request");
chg.addQuery('sys_id',current.change_request);
chg.query();
if(chg.next())
{
    gs.log('type'+chg.type);
    var change_type= chg.type;
}
    if (((current.short_description == "Post implementation testing") && (change_type == 'normal' || change_type == 'standard')) || (current.short_description == 'implementation' && (change_type == 'emergency'))) {
var attachmentGR = new GlideAggregate('sys_attachment');
            attachmentGR.addAggregate('COUNT');
            attachmentGR.addQuery('table_name', 'change_task'); // Change Task table
            attachmentGR.addQuery('table_sys_id',current.sys_id); // Current Change Task record
            attachmentGR.query();
         
            if (attachmentGR.next()) {
var attachcount = attachmentGR.getAggregate('COUNT');

}

}
if(attachcount == 0)
{
 gs.addErrorMessage('The attachment of the sanity implementation test result is mandatory before closing the post-implementation testing CTASK');
   current.setAbortAction(true);
   current.state = previous.state;
   current.setRedirectURL(current);
}
 

})(current, previous);
 
any one can help on this code
5 REPLIES 5

Community Alums
Not applicable

Hi @MK21 

 

Try this…

 

 

(function executeRule(current, previous /*null when async*/ ) {
    var chg = new GlideRecord("change_request");
    chg.addQuery('sys_id', current.change_request);
    chg.query();
    if (chg.next()) {
        gs.log('type' + chg.type);
        var change_type = chg.type;
    }

    if (((current.short_description == "Post implementation testing") && (change_type == 'normal' || change_type == 'standard')) || (current.short_description == 'implementation' && (change_type == 'emergency'))) {
        var attachmentGR = new GlideAggregate('sys_attachment');
        attachmentGR.addAggregate('COUNT');
        attachmentGR.addQuery('table_name', 'change_task'); // Change Task table
        attachmentGR.addQuery('table_sys_id', current.sys_id); // Current Change Task record
        attachmentGR.query();

        if (attachmentGR.next()) {
            var attachcount = attachmentGR.getAggregate('COUNT');
            if (attachcount == 0) {
                gs.addErrorMessage('The attachment of the sanity implementation test result is mandatory before closing the post-implementation testing CTASK');
                current.setAbortAction(true);
                current.state = previous.state;
                current.setRedirectURL(current);
            }
        }
    }
})(current, previous);

 

Please mark as helpful or if it’s resolved the issue, CORRECT!

where you change the code and in the short description for emergency change is implementation task 

 

can u please chekc

Sohail Khilji
Kilo Patron

What's you question, can you be clear....


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Hi,

 

in Emergency change change task short description is implementation task but in code i write implementation ,my need is when i am trying to close this task will it through error attachment is mandatory like 

MK21_0-1708449647466.png