Importing CSV file in Record producer and then fetching the CSV file records in Business Rule

Nishant26
Tera Contributor

Hi All,

 

I have a requirement where I need to import the CSV file in Record Producer. Once the record is submitted, it will redirect to a different table(u_abc). Now, I need to create a business rule on this table(u_abc) when the record is inserted in table(u_abc) in order to trigger the subflow which I am using for CI creation. 

 

In the business rule, I need to fetch the records from the CSV file which will be used as inputs for the subflow.

 

I need help with the Business Rule code to implement the same.

 

Thanks!

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@Nishant26 create an onAfter Insert business rule on u_abc table.

 

Write the following script to fetch the attachment from sys_attachment table.

 

var glideAttachment = new GlideRecord('sys_attachment');
glideAttachment.addQuery('table_sys_id',current.getValue('sys_id'));
glideAttachment.addQuery()
glideAttachment.query();
if(glideAttachment.next()){
var parser = new sn_impex.GlideExcelParser(); 
var attachment = new GlideSysAttachment();
// use attachment sys id of an excel file
var attachmentStream = attachment.getContentStream(glideAttachment.getValue('sys_id'));

parser.parse(attachmentStream); 

//retrieve the column headers
var headers = parser.getColumnHeaders();  
var header1 = headers[0]; 
var header2 = headers[1]; 

//print headers
gs.info(header1 + " " + header2); 

while(parser.next()) { 
  var row = parser.getRow(); 
  //print row value for both columns   
  gs.info(row[header1] + ' ' + row[header2]) 
}
parser.close(); // close the stream and release the document
}

Please refer to this URL https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server/sn_impex-namespace/GlideExcelPa... to get more information on GlideExcelParser

 

Hope this helps

Hi @Sandeep Rajput , I also need to copy the attachment from Record producer to the table(u_abc)

but there is a problem in the table name on sys_attachment table. when a record is inserted in the sys_attachment table, it is appearing as "ZZ_YYu_abc" in the table name field. this is creating an issue while updating the attachment record to u_abc table.

 

I need to remove the "ZZ_YY" from the prefix in the table name field on sys_attachment table.

Here is the code:

var gr = new GlideRecord('sys_attachment');
if(gr.get(producer.number_list)){ //attachment field name
    gr.table_name='u_abc';     //copy to table name
    gr.table_sys_id=current.sys_id;//copy to record sys_id
    gr.update();
    
}

@Nishant26 Please refer to the solution posted on this thread https://www.servicenow.com/community/now-platform-forum/disable-zz-yy-prefix-from-attachment-when-ad....

 

Hope this helps.