Export a table data

kirankr2061
Tera Contributor

Hi all, I’d like your thoughts on this.

We’ve received a requirement where we need to extract data from a specific table in ServiceNow and send it to an Azure console (such as a storage account) as a CSV file. This process needs to be automated to run every Saturday.

What would be the best approach to achieve this? Specifically, how can we generate the CSV file and send it as an attachment to the Azure endpoint on a scheduled basis?

Any suggestions or best practices would be appreciated!

4 REPLIES 4

Periyasamy P
Tera Guru

If you can able to pick csv from MID server, then you can use export set for your use case.

Otherwise, you can create scheduled job (script) to upload data.

 Step 1: Query your target table

 Step 2: Create attachment and store the attachment in scheduled job

 Step 3: REST call to upload attachment to target

 

/* Query your target table and store valus in variable*/
var string = "Number,Name\n";
var gr = new GlideRecord('<target table>');
gr.query();
while (gr.next()) {
  string += gr.getValue("number") + "," + gr.getValue("name") + "\n";
}


var rec = new GlideRecord('<scheduled job>');
rec.get('<sys_id>');

var fileName = 'Your records.csv';
var contentType = 'text/csv';

var attachment = new GlideSysAttachment();

/* Create attachment and add it to scheduled job */
var agr = attachment.write(rec, fileName, contentType, string);

 

Ankur Bawiskar
Tera Patron
Tera Patron

@kirankr2061 

You can follow this approach and stick to the OOTB mechanism and less maintenance from ServiceNow point of view.

1) Use Export Set feature and push csv file daily to mid server location. you can push complete table records or push delta records.

2) ask the Customer team to write some powershell script to upload that file to Azure

Export sets 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@kirankr2061 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@kirankr2061 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader