Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

help to extract the attached CSV File in RITM.

jyotimalhot
Tera Contributor

Hi Team,

 

I need help to extract the attached CSV File in RITM. Is there any way we can extract the CSV file?

 

jyotimalhot_0-1726714537350.png

 

 

Thanks

JM

6 REPLIES 6

Hi Swapna,

 

But how I can import the attachment from RITM table?

 

Thanks

JM

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