
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 01:34 PM
Hello everyone, I have a requirement where I need to copy the attachments from the variables on my RITM to the record itself. I have already looked at the sys_attachment table, but I couldn't find a table with these table names'.
I also tried to search for the sys_id, without success either.
Is it possible to be done?
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 03:37 PM
You can create an async Insert Business Rule on the sc_req_item table. If you want the attachment(s) to appear in the header instead of the activity stream, use this script.
(function executeRule(current, previous /*null when async*/) {
var attach = new GlideRecord('sys_attachment');
attach.addQuery('table_name', 'ZZ_YY' + current.getTableName());
attach.addQuery('table_sys_id', current.sys_id);
attach.query();
while(attach.next()){
attach.table_name = current.getTableName();
attach.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 03:37 PM
You can create an async Insert Business Rule on the sc_req_item table. If you want the attachment(s) to appear in the header instead of the activity stream, use this script.
(function executeRule(current, previous /*null when async*/) {
var attach = new GlideRecord('sys_attachment');
attach.addQuery('table_name', 'ZZ_YY' + current.getTableName());
attach.addQuery('table_sys_id', current.sys_id);
attach.query();
while(attach.next()){
attach.table_name = current.getTableName();
attach.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2021 04:20 PM
Also you can do it with the exact attachments uploaded to the variables. The other type may include attachments being cleared from the value based on UI Policy or Catalog Client script.
(function executeRule(current, previous /*null when async*/ ) {
var attachmentsSysIDs = '';
var gr = new GlideRecord('sc_item_option_mtom');
gr.addEncodedQuery('request_item=' + current.sys_id + '^sc_item_option.item_option_new.type=33');
gr.query();
while (gr.next()) {
attachmentsSysIDs += gr.sc_item_option.value + ",";
}
var attach = new GlideRecord('sys_attachment');
attach.addQuery('sys_id', 'IN', attachmentsSysIDs);
attach.query();
while (attach.next()) {
attach.table_name = current.getTableName();
attach.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2021 02:59 PM
Becareful using the above script. If you are doing
attach.update();
Make sure you handle when user deletes the attachment. Other wise the RITM and TASK form will not render anymore. You need to handle the MTOM update for that attachment variable.