<?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 Onbefore script transfrom map in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/onbefore-script-transfrom-map/m-p/2870533#M1096618</link>
    <description>&lt;P&gt;Hello Experts,&lt;/P&gt;&lt;P&gt;I'm currently delving into the sources.row method within a transform map script. I have an Excel sheet containing ten records, and I'm looking to import only two specific records: those corresponding to rows 1 and 5. However, despite writing the following script, it doesn't seem to be functioning correctly. Could someone please guide me on this?&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;Onbefore Script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

	if(source.row==1 ||source.row==5)
	{

gs.log("do nothing");
	}
	else{
gs.log("Ignore records"+source.row);
	ignore=true;
	}

})(source, map, log, target);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Mar 2024 06:15:00 GMT</pubDate>
    <dc:creator>abhijee</dc:creator>
    <dc:date>2024-03-20T06:15:00Z</dc:date>
    <item>
      <title>Onbefore script transfrom map</title>
      <link>https://www.servicenow.com/community/developer-forum/onbefore-script-transfrom-map/m-p/2870533#M1096618</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;&lt;P&gt;I'm currently delving into the sources.row method within a transform map script. I have an Excel sheet containing ten records, and I'm looking to import only two specific records: those corresponding to rows 1 and 5. However, despite writing the following script, it doesn't seem to be functioning correctly. Could someone please guide me on this?&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;Onbefore Script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

	if(source.row==1 ||source.row==5)
	{

gs.log("do nothing");
	}
	else{
gs.log("Ignore records"+source.row);
	ignore=true;
	}

})(source, map, log, target);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 06:15:00 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/onbefore-script-transfrom-map/m-p/2870533#M1096618</guid>
      <dc:creator>abhijee</dc:creator>
      <dc:date>2024-03-20T06:15:00Z</dc:date>
    </item>
    <item>
      <title>Re: Onbefore script transfrom map</title>
      <link>https://www.servicenow.com/community/developer-forum/onbefore-script-transfrom-map/m-p/2870610#M1096642</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/536073"&gt;@abhijee&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;The `onBefore` script in a ServiceNow transform map is used to manipulate data before it is transformed into the target table. If you want to import only the records from rows 1 and 5, you should set `ignore` to `true` for all other rows except for rows 1 and 5. However, the `source.row` property does not exist in ServiceNow's data source API. Instead, you should use `source.getRow()` to get the current row number.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Here's how you can modify your script to correctly ignore all rows except for 1 and 5:&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
    var currentRow = source.getRow(); // Get the current row number

    if (currentRow == 1 || currentRow == 5) {
        // If it's row 1 or 5, do not ignore (import the record)
        gs.log("Importing record from row: " + currentRow);
    } else {
        // If it's any other row, ignore (do not import the record)
        gs.log("Ignoring record from row: " + currentRow);
        ignore = true; // Set ignore to true to skip the record
    }
})(source, map, log, target);&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;Make sure to place this script in the `onBefore` script field of your transform map. This script will log a message for each row that is processed, indicating whether the row is being imported or ignored. Only rows 1 and 5 will be imported, and all other rows will be ignored.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P class="p1"&gt;&lt;STRONG&gt;&lt;I&gt;Please mark this response as correct or helpful if it assisted you with your question.&lt;/I&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 07:11:31 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/onbefore-script-transfrom-map/m-p/2870610#M1096642</guid>
      <dc:creator>Iraj Shaikh</dc:creator>
      <dc:date>2024-03-20T07:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: Onbefore script transfrom map</title>
      <link>https://www.servicenow.com/community/developer-forum/onbefore-script-transfrom-map/m-p/2870889#M1096713</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/278239"&gt;@Iraj Shaikh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your assistance.&lt;/P&gt;&lt;P&gt;I attempted to use the script you provided in the OnBefore script event, but it doesn't seem to be functioning correctly. In the system log, I noticed that the current row is showing as &lt;STRONG&gt;undefined&lt;/STRONG&gt;. I have attached a screenshot for your reference.&lt;/P&gt;&lt;P&gt;Thank You.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 10:07:00 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/onbefore-script-transfrom-map/m-p/2870889#M1096713</guid>
      <dc:creator>abhijee</dc:creator>
      <dc:date>2024-03-20T10:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: Onbefore script transfrom map</title>
      <link>https://www.servicenow.com/community/developer-forum/onbefore-script-transfrom-map/m-p/2870924#M1096724</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/536073"&gt;@abhijee&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you try the following instead:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;source.getValue('sys_import_row') == 1 || source.getValue('sys_import_row') == 5&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And FYI, I don't think using the row to ignore the data is recommended. Instead, you should define a logic by using the actual value of the imported data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 10:25:40 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/onbefore-script-transfrom-map/m-p/2870924#M1096724</guid>
      <dc:creator>James Chun</dc:creator>
      <dc:date>2024-03-20T10:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Onbefore script transfrom map</title>
      <link>https://www.servicenow.com/community/developer-forum/onbefore-script-transfrom-map/m-p/2872383#M1097154</link>
      <description>&lt;P&gt;Thank You&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/594931"&gt;@James Chun&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Its working.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 08:41:02 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/onbefore-script-transfrom-map/m-p/2872383#M1097154</guid>
      <dc:creator>abhijee</dc:creator>
      <dc:date>2024-03-21T08:41:02Z</dc:date>
    </item>
  </channel>
</rss>

