help to extract the attached CSV File in RITM.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 07:57 PM
Hi Team,
I need help to extract the attached CSV File in RITM. Is there any way we can extract the CSV file?
Thanks
JM
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 12:24 AM
Hi Swapna,
But how I can import the attachment from RITM table?
Thanks
JM
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 08:35 PM
Hi Swapna,
I'm trying via Business Rule script, but not sure the best script.
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('312a741447701210f42eb87b716d4337', current.sys_id); // sys_id of the current RITM
attachmentGR.addQuery('cmdb_ci_outage (2) (1).csv', 'CONTAINS', '.csv'); // Check for CSV attachments
attachmentGR.query();
if (attachmentGR.hasNext()) {
gs.info('CSV attachment found for RITM: ' + current.number);
} else {
gs.info('No CSV attachment found for RITM: ' + current.number);
}
while (attachmentGR.next()) {
// Log the attachment details
gs.info('Processing attachment: ' + attachmentGR.cmdb_ci_outage(2));
// Extract and process the CSV file
var attachment = new GlideSysAttachment();
var contentStream = attachment.getContentStream(attachmentGR.sys_id);
// Use GlideTextReader to read CSV line by line
var reader = new GlideTextReader(contentStream);
var line;
while ((line = reader.readLine()) != null) {
// Log each line being processed
gs.info('Processing CSV line: ' + line);
}
}
// Log the end of the script execution
gs.info('Business Rule: Extract CSV from RITM Attachment - finished for RITM: ' + current.number);
Thanks
JM