How to attach a document to a task/cart from a scheduled job

Joshua Comeau
Kilo Sage

Here is my script:

JoshuaComeau_0-1714488224713.png

I want to know when an attachment is attached to the form of the scheduled job what script to I place in this code that will glide the current document and stamp it on either the cart of the catalog or on the task that is generated?

 

1 ACCEPTED SOLUTION

Joshua Comeau
Kilo Sage
Solution that worked for me:
 
//To Bulk update this script: System Data Management > Update Jobs
try{ //DO NOT TOUCH
 
var cartId = GlideGuid.generate(null); //CartID Generates //DO NOT TOUCH
var cart = new Cart(cartId); //Creates New Cart //DO NOT TOUCH
//add your requested item to the cart by sys_id of the catalog item //DO NOT TOUCH
var item = cart.addItem('7893bd301b90f110e010dd3bdc4bcbca', 1); //Adds Facility Request Catalog //DO NOT TOUCH

//Auto Populate the short description and description
var shortdesc = gs.info(current.u_ppm_short_description);
cart.setVariable(item, 'what_can_we_help_you_with', current.u_ppm_short_description);

var desc = gs.info(current.u_ppm_description);
cart.setVariable(item, 'can_you_give_us_some_more_details', current.u_ppm_description);

var article = gs.info(current.u_knowledge_article);
cart.setVariable(item, 'knowledge_article', current.u_knowledge_article);


var rc = cart.placeOrder(); //Places Order //DO NOT TOUCH

//Search for the scheduled job attachment and attach to the sctask
var attachment = new GlideSysAttachment();
var glideRITM = new GlideRecord('sc_req_item');
glideRITM.addQuery('request', rc.getValue('sys_id'));
glideRITM.query();
while (glideRITM.next()) {
    var glideSCTask = new GlideRecord('sc_task');
    glideSCTask.addQuery('request_item', glideRITM.getValue('sys_id'));
    glideSCTask.query();
    while (glideSCTask.next()) {
        //Copy attachment here
        var attachmentSysID = attachment.copy('sysauto_script', current.getValue('sys_id'), 'sc_task', glideSCTask.getValue('sys_id'));
        gs.info('Attachment with sys_id ' + attachmentSysID + ' to SCTask ' + glideSCTask.number);
    }
}

gs.info(rc.number); //DO NOT TOUCH
}//DO NOT TOUCH
catch(ex){//DO NOT TOUCH
gs.info(ex);//DO NOT TOUCH

}//DO NOT TOUCH
//end

View solution in original post

1 REPLY 1

Joshua Comeau
Kilo Sage
Solution that worked for me:
 
//To Bulk update this script: System Data Management > Update Jobs
try{ //DO NOT TOUCH
 
var cartId = GlideGuid.generate(null); //CartID Generates //DO NOT TOUCH
var cart = new Cart(cartId); //Creates New Cart //DO NOT TOUCH
//add your requested item to the cart by sys_id of the catalog item //DO NOT TOUCH
var item = cart.addItem('7893bd301b90f110e010dd3bdc4bcbca', 1); //Adds Facility Request Catalog //DO NOT TOUCH

//Auto Populate the short description and description
var shortdesc = gs.info(current.u_ppm_short_description);
cart.setVariable(item, 'what_can_we_help_you_with', current.u_ppm_short_description);

var desc = gs.info(current.u_ppm_description);
cart.setVariable(item, 'can_you_give_us_some_more_details', current.u_ppm_description);

var article = gs.info(current.u_knowledge_article);
cart.setVariable(item, 'knowledge_article', current.u_knowledge_article);


var rc = cart.placeOrder(); //Places Order //DO NOT TOUCH

//Search for the scheduled job attachment and attach to the sctask
var attachment = new GlideSysAttachment();
var glideRITM = new GlideRecord('sc_req_item');
glideRITM.addQuery('request', rc.getValue('sys_id'));
glideRITM.query();
while (glideRITM.next()) {
    var glideSCTask = new GlideRecord('sc_task');
    glideSCTask.addQuery('request_item', glideRITM.getValue('sys_id'));
    glideSCTask.query();
    while (glideSCTask.next()) {
        //Copy attachment here
        var attachmentSysID = attachment.copy('sysauto_script', current.getValue('sys_id'), 'sc_task', glideSCTask.getValue('sys_id'));
        gs.info('Attachment with sys_id ' + attachmentSysID + ' to SCTask ' + glideSCTask.number);
    }
}

gs.info(rc.number); //DO NOT TOUCH
}//DO NOT TOUCH
catch(ex){//DO NOT TOUCH
gs.info(ex);//DO NOT TOUCH

}//DO NOT TOUCH
//end