Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 07:44 AM
Here is my script:
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?
Solved! Go to Solution.
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 08:08 AM
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
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 08:08 AM
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