<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Script to remain leading zeroes of a number in pre-export script in SPM forum</title>
    <link>https://www.servicenow.com/community/spm-forum/script-to-remain-leading-zeroes-of-a-number-in-pre-export-script/m-p/3009969#M44169</link>
    <description>&lt;P&gt;Hi Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm facing an issue with the string type field which is removing the leading zeroes of a number when exporting report to mid server in csv file format.&lt;/P&gt;&lt;P&gt;Example, the employee number 00123, after export the report to mid server using export set, the number updated as "123".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Appreciate if someone could provide a script in&amp;nbsp;export set pre-export script to add&amp;nbsp;apostrophe in front of the number so that the leading zeros remain.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Aug 2024 02:25:39 GMT</pubDate>
    <dc:creator>Nur1</dc:creator>
    <dc:date>2024-08-06T02:25:39Z</dc:date>
    <item>
      <title>Script to remain leading zeroes of a number in pre-export script</title>
      <link>https://www.servicenow.com/community/spm-forum/script-to-remain-leading-zeroes-of-a-number-in-pre-export-script/m-p/3009969#M44169</link>
      <description>&lt;P&gt;Hi Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm facing an issue with the string type field which is removing the leading zeroes of a number when exporting report to mid server in csv file format.&lt;/P&gt;&lt;P&gt;Example, the employee number 00123, after export the report to mid server using export set, the number updated as "123".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Appreciate if someone could provide a script in&amp;nbsp;export set pre-export script to add&amp;nbsp;apostrophe in front of the number so that the leading zeros remain.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2024 02:25:39 GMT</pubDate>
      <guid>https://www.servicenow.com/community/spm-forum/script-to-remain-leading-zeroes-of-a-number-in-pre-export-script/m-p/3009969#M44169</guid>
      <dc:creator>Nur1</dc:creator>
      <dc:date>2024-08-06T02:25:39Z</dc:date>
    </item>
    <item>
      <title>Re: Script to remain leading zeroes of a number in pre-export script</title>
      <link>https://www.servicenow.com/community/spm-forum/script-to-remain-leading-zeroes-of-a-number-in-pre-export-script/m-p/3010005#M44171</link>
      <description>&lt;P&gt;Below is sample code to add to your export set's pre-export script that will add a leading apostrophe to any numeric values ​​in the specified field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(function() {
    // Field name to export
    var fieldName = 'employee_number'; // Specify the field name to be exported

    // Retrieve records for export
    var gr = new GlideRecord('your_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 &amp;amp;&amp;amp; fieldValue.match(/^\d+$/)) {
            // Add an apostrophe at the beginning of the number
            var formattedValue = "'" + fieldValue;
            gr.setValue(fieldName, formattedValue);
            gr.update();
        }
    }
})();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2024 03:38:28 GMT</pubDate>
      <guid>https://www.servicenow.com/community/spm-forum/script-to-remain-leading-zeroes-of-a-number-in-pre-export-script/m-p/3010005#M44171</guid>
      <dc:creator>HIROSHI SATOH</dc:creator>
      <dc:date>2024-08-06T03:38:28Z</dc:date>
    </item>
    <item>
      <title>Re: Script to remain leading zeroes of a number in pre-export script</title>
      <link>https://www.servicenow.com/community/spm-forum/script-to-remain-leading-zeroes-of-a-number-in-pre-export-script/m-p/3010410#M44180</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried the script that you have provided but the apostrophe is&amp;nbsp;not a&lt;SPAN&gt;dded to the field.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Actually the Export Definition from Export Set is coming from Database View which join 3 tables (refer to the attachment below). Btw the excel header display as table_name.field_name (dot walk) once exported to CSV.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me with the solution/ scripts&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to know what is the difference between pre-script &amp;amp; post-script ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Aug 2024 06:38:49 GMT</pubDate>
      <guid>https://www.servicenow.com/community/spm-forum/script-to-remain-leading-zeroes-of-a-number-in-pre-export-script/m-p/3010410#M44180</guid>
      <dc:creator>Nur1</dc:creator>
      <dc:date>2024-08-07T06:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: Script to remain leading zeroes of a number in pre-export script</title>
      <link>https://www.servicenow.com/community/spm-forum/script-to-remain-leading-zeroes-of-a-number-in-pre-export-script/m-p/3010939#M44184</link>
      <description>&lt;H3&gt;&lt;FONT&gt;&lt;FONT&gt;In this case, I think it should be processed with "Pre-Processing Script".&lt;/FONT&gt;&lt;/FONT&gt;&lt;/H3&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H3&gt;&lt;FONT&gt;&lt;FONT&gt;前処理スクリプト&lt;/FONT&gt;&lt;/FONT&gt;&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;目的&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;: このスクリプトは、インポート プロセスが開始される前に実行されます。インポートする前にデータを準備、検証、または変換するために使用されます。&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;使用例&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;: データのクレンジング、変換、フィールドの前処理、外部データの取得など。&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;実行タイミング&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;: データが ServiceNow にロードされる前に実行されます。&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;例&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;: フィールド値の標準化、データの検証、エラーのログ記録。&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;H3&gt;&lt;FONT&gt;&lt;FONT&gt;後処理スクリプト&lt;/FONT&gt;&lt;/FONT&gt;&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;目的&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;: このスクリプトは、データがインポートされた後に実行されます。インポート プロセスが完了したら、追加の処理または検証に使用されます。&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;ユースケース&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;: 追加のデータ処理、データの関連付け、トリガーまたはアラートの作成など。&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;実行タイミング&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;: データが ServiceNow にロードされた後に実行されます。&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;例&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;: インポートされたデータに基づいて他のテーブルにデータを挿入したり、関連レコードを更新したり、ビジネス ルールやワークフローをトリガーしたりします。&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;H3&gt;&lt;FONT&gt;&lt;FONT&gt;まとめ&lt;/FONT&gt;&lt;/FONT&gt;&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;前処理スクリプト&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;: インポート前にデータを準備または変更します。&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;後処理スクリプト&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT&gt;&lt;FONT&gt;: インポート後に追加の処理または検証を実行します。&lt;/FONT&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Tue, 06 Aug 2024 15:48:35 GMT</pubDate>
      <guid>https://www.servicenow.com/community/spm-forum/script-to-remain-leading-zeroes-of-a-number-in-pre-export-script/m-p/3010939#M44184</guid>
      <dc:creator>HIROSHI SATOH</dc:creator>
      <dc:date>2024-08-06T15:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: Script to remain leading zeroes of a number in pre-export script</title>
      <link>https://www.servicenow.com/community/spm-forum/script-to-remain-leading-zeroes-of-a-number-in-pre-export-script/m-p/3010960#M44187</link>
      <description>&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Navigate to your Export Set&lt;/STRONG&gt;:&lt;BR /&gt;Go to the Export Set you are using for the export.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Create an Export Script&lt;/STRONG&gt;:&lt;BR /&gt;Add the following script to the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Export Set&lt;/STRONG&gt;. This script will add an apostrophe before numeric fields:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(function() {
    var tableName = 'your_table_name'; // Replace with your table name
    var fieldName = 'employee_number'; // Replace with your field name

    // Combine table name and field name for CSV export
    var csvFieldName = tableName + '.' + fieldName;

    var gr = new GlideRecord(tableName);
    gr.query();

    while (gr.next()) {
        var fieldValue = gr.getValue(csvFieldName);
        if (fieldValue &amp;amp;&amp;amp; !fieldValue.startsWith("'")) {
            gr.setValue(csvFieldName, "'" + fieldValue);
            gr.update();
        }
    }
})();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Replace&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;'employee_number'&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;with the actual field name containing the numbers.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Replace&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;'your_table_name'&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;with the actual table name where the data is stored.&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Execute the Export&lt;/STRONG&gt;:&lt;BR /&gt;Run your export set as usual. The leading zeros should be preserved in the CSV file.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Tue, 06 Aug 2024 16:10:23 GMT</pubDate>
      <guid>https://www.servicenow.com/community/spm-forum/script-to-remain-leading-zeroes-of-a-number-in-pre-export-script/m-p/3010960#M44187</guid>
      <dc:creator>HIROSHI SATOH</dc:creator>
      <dc:date>2024-08-06T16:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: Script to remain leading zeroes of a number in pre-export script</title>
      <link>https://www.servicenow.com/community/spm-forum/script-to-remain-leading-zeroes-of-a-number-in-pre-export-script/m-p/3011330#M44192</link>
      <description>&lt;P&gt;Hi Hiroshi,&lt;/P&gt;&lt;P&gt;I've tried using your script in Scheduled Exports &amp;gt;&amp;nbsp;&lt;SPAN&gt;Execute pre-export script. Unluckily the apostrophe still not appended in the employee_number field once the report generated to mid server. Is there any other script that would make this works ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Aug 2024 04:01:39 GMT</pubDate>
      <guid>https://www.servicenow.com/community/spm-forum/script-to-remain-leading-zeroes-of-a-number-in-pre-export-script/m-p/3011330#M44192</guid>
      <dc:creator>Nur1</dc:creator>
      <dc:date>2024-08-07T04:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: Script to remain leading zeroes of a number in pre-export script</title>
      <link>https://www.servicenow.com/community/spm-forum/script-to-remain-leading-zeroes-of-a-number-in-pre-export-script/m-p/3012095#M44200</link>
      <description>&lt;LI-CODE lang="markup"&gt;Try changing the table to a database view and running it.
 
var gr = new GlideRecord(tableName);
↓
var gr = new GlideRecord(viewName);&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 07 Aug 2024 15:18:12 GMT</pubDate>
      <guid>https://www.servicenow.com/community/spm-forum/script-to-remain-leading-zeroes-of-a-number-in-pre-export-script/m-p/3012095#M44200</guid>
      <dc:creator>HIROSHI SATOH</dc:creator>
      <dc:date>2024-08-07T15:18:12Z</dc:date>
    </item>
  </channel>
</rss>

