Zero value is not visible when export report to CSV format

Nur1
Tera Contributor

Hi community, currently we want to do export set to drop file to mid server. We have case where employee number initial with number 0. When the system export the file as CSV to mid server, the 0 is missing from the file. As I know, we need to put apostrophe in front of the number. How to write a script to cater this and where do I need to put the scripting at ?

 

Please help. Thanks

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Nur1 

may be it's considering it as integer and hence stripping the zero

you can try to use export set pre-export script and handle the csv file manipulation

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

Hi Ankur,

Actually the Export Definition from Export Set is coming from Database View which join 3 tables (refer attachment). The header in the excel is display as table_name.field_name. Kindly refer to the script below and I'm not able to append the apostrophe. Kindly help to provide with your script/ solutions.

 

 

(function() {
    // Field name to export
    var fieldName = 'table_name.field_name'; // Specify the field name to be exported

    // Retrieve records for export
    var gr = new GlideRecord('table_name'); // Specify the table name to target
    gr.query();
    while (gr.next()) {
        var fieldValue = gr.getValue(fieldName);

        // Add an apostrophe at the beginning of the number to preserve leading zeros
        if (fieldValue && fieldValue.match(/^\d+$/)) {
            // Add an apostrophe at the beginning of the number
            var formattedValue = "'" + fieldValue;
            gr.setValue(fieldName, formattedValue);
            gr.update();
        }
    }
})();
 
Nur1_0-1722937283481.png