Generate CSV report out of Flow designer Action

Kishore32
Tera Contributor

Hello,

I'm having a Flow that fetch records using 'Loop up records' based on some condition and if condition satisfies then have to update the record.

Before updating the record I would like to generate a CSV file from the 'Look up records' to ensure the data is correct.

Is there any way that we can generate a report out of Flow action? any other suggestions?

Thanks,

Kishore.

4 REPLIES 4

Service_RNow
Mega Sage

HI,

please refer the below link you can find some interesting info:-

https://community.servicenow.com/community?id=community_article&sys_id=e5ad70d61b1d4490d01143f6fe4bc...

Mark the comment as a correct answer and also helpful if this helps.

Thanks for quick response!!

I'm looking for to create a report csv file some where in my machine from the below action. Not to attach to a record. Please help me here with any other suggestion.

find_real_file.png

Hi @Kishore32 
I have similar requirement, did you get the solution for this?

Mani A
Tera Guru

Create custom script action

 

Sample code:

(function execute(inputs, outputs) {

    var csvGenerator = new CSVGenerator();

    var records = [];

    

    // Assuming `inputs.records` is the array of records from the Lookup Records action

    records = inputs.records.map(function(record) {

        return {

            field1: record.field1,

            field2: record.field2,

            field3: record.field3

        };

    });

    

    var csvContent = csvGenerator.generateCSV(records);

    

    // Store or send the CSV content

    // Optionally, you could save this to a file or send it via email

 

    outputs.csvContent = csvContent; // Pass the CSV content to be used in subsequent actions

})(inputs, outputs);

 

var CSVGenerator = Class.create();

CSVGenerator.prototype = {

    initialize: function() {},

 

    generateCSV: function(records) {

        var csv = '';

        var header = 'Field1,Field2,Field3\n'; // Adjust header based on your fields

        csv += header;

 

        records.forEach(function(record) {

            var line = '';

            line += record.field1 + ','; // Adjust field names based on your data

            line += record.field2 + ',';

            line += record.field3 + '\n';

            csv += line;

        });

 

        return csv;

    },

 

    type: 'CSVGenerator'

};