<?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 Re: Bulk Upload in Staging Table Though Scripted RestApi in ITSM forum</title>
    <link>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884310#M456089</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;create new scripted rest api and new scripted rest resource&lt;/P&gt;
&lt;P&gt;Rest Resource -&amp;gt; POST Method&lt;/P&gt;
&lt;P&gt;Script below:&lt;/P&gt;
&lt;P&gt;1) iterate over the body&lt;/P&gt;
&lt;P&gt;2) parse the json&lt;/P&gt;
&lt;P&gt;3) for every object from the array&lt;/P&gt;
&lt;P&gt;Sample below: Ensure you are receiving the above json request; I have assumed the json key is the column name&lt;/P&gt;
&lt;P&gt;Also use proper import set table in GlideRecord&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
	
	var requestBody = request.body.dataString;
	var parser = new global.JSON();
	var parsedData = parser.decode(requestBody);
	
	for(var i=0;i&amp;lt;parsedData.length;i++){
		
		
		var gr = new GlideRecord('cmdb_test');
		gr.initialize();
		gr.u_displayname = parsedData[i].u_displayname;
		gr.u_vendor = parsedData[i].u_vendor;
		gr.u_primaryipv4address = parsedData[i].u_primaryipv4address;
		gr.u_primaryosversion = parsedData[i].u_primaryosversion;
		gr.u_primaryostype = parsedData[i].u_primaryostype;
		gr.u_osdescription = parsedData[i].u_osdescription;
		gr.u_physserialnumber = parsedData[i].u_physserialnumber;
		gr.u_primarydnsname = parsedData[i].u_primarydnsname;
		gr.insert();	
	}	
	var responseBody = {};
	responseBody.status = "Success";
	response.setBody(responseBody);
	
	
})(request, response);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Mark &lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; Correct if this solves your issue and also mark &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt; Helpful if you find my response worthy based on the impact.&lt;BR /&gt;Thanks&lt;BR /&gt;Ankur&lt;/P&gt;</description>
    <pubDate>Fri, 15 May 2020 10:15:33 GMT</pubDate>
    <dc:creator>Ankur Bawiskar</dc:creator>
    <dc:date>2020-05-15T10:15:33Z</dc:date>
    <item>
      <title>Bulk Upload in Staging Table Though Scripted RestApi</title>
      <link>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884307#M456086</link>
      <description>&lt;P&gt;Hi Folks,&lt;/P&gt;
&lt;P&gt;I have requirement in which Bulk Upload is require through External source in CMDB , I have created a Import Set Table and now i need whenever External source hit the ServiceNow API the whole data is dumping in staging table and after that transform maps are triggered. Earlier Row by Row is coming from external source and through Import Set Api it was working fine but now if Bulk Data is coming&amp;nbsp; the Import Set APi could not accept the data except 1st row as OOTB functionality.&lt;/P&gt;
&lt;P&gt;I know this can be achieve by Scripted RestApi But i don't how to write exact logic so that whole bunch of data is dumping in Staging Table.&lt;/P&gt;
&lt;P&gt;the data is coming like below JSON Format in one Array.&lt;/P&gt;
&lt;P&gt;[{&lt;BR /&gt; "u_displayname": "abc123",&lt;BR /&gt; "u_vendor": "Cisco",&lt;BR /&gt; "u_primaryipv4address": "10.1.1.2",&lt;BR /&gt; "u_primaryosversion": "1.2.3.5",&lt;BR /&gt; "u_primaryostype": "Cisco IOS",&lt;BR /&gt; "u_osdescription": "Cisco IOS Software",&lt;BR /&gt; "u_physserialnumber": "abc123xyz",&lt;BR /&gt; "u_primarydnsname": "abc123.abc.com"&lt;BR /&gt; },&lt;BR /&gt; { &lt;BR /&gt; "u_displayname": "abc123",&lt;BR /&gt; "u_vendor": "Microsoft",&lt;BR /&gt; "u_primaryipv4address": "10.1.1.3",&lt;BR /&gt; "u_primaryosversion": "1.2.3.6",&lt;BR /&gt; "u_primaryostype": "Cisco IOS",&lt;BR /&gt; "u_osdescription": "Cisco IOS Software",&lt;BR /&gt; "u_physserialnumber": "abc123xyz",&lt;BR /&gt; "u_primarydnsname": "abc123.abc.com"&lt;BR /&gt; },&lt;BR /&gt; {&lt;BR /&gt; &lt;BR /&gt; "u_displayname": "abc123",&lt;BR /&gt; "u_vendor": "HP",&lt;BR /&gt; "u_primaryipv4address": "10.1.1.4",&lt;BR /&gt; "u_primaryosversion": "1.2.3.7",&lt;BR /&gt; "u_primaryostype": "Cisco IOS",&lt;BR /&gt; "u_osdescription": "Cisco IOS Software",&lt;BR /&gt; "u_physserialnumber": "abc123xyz",&lt;BR /&gt; "u_primarydnsname": "abc123.abc.com"&lt;BR /&gt; }&lt;BR /&gt;]&lt;/P&gt;
&lt;P&gt;If any one has solution of this requirement it would be great help&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;Yad&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 May 2020 09:43:43 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884307#M456086</guid>
      <dc:creator>yadi</dc:creator>
      <dc:date>2020-05-15T09:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk Upload in Staging Table Though Scripted RestApi</title>
      <link>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884308#M456087</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;If you use scripted rest API you will have to inform the 3rd party team about the change in endpoint;&lt;/P&gt;
&lt;P&gt;in scripted rest API do this&lt;/P&gt;
&lt;P&gt;1) accept the request body&lt;/P&gt;
&lt;P&gt;2) parse the json body&lt;/P&gt;
&lt;P&gt;3) for every json object in the array create record in import set using GlideRecord&lt;/P&gt;
&lt;P&gt;It would trigger the transform map&lt;/P&gt;
&lt;P&gt;Mark &lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; Correct if this solves your issue and also mark &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt; Helpful if you find my response worthy based on the impact.&lt;BR /&gt;Thanks&lt;BR /&gt;Ankur&lt;/P&gt;</description>
      <pubDate>Fri, 15 May 2020 09:50:23 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884308#M456087</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2020-05-15T09:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk Upload in Staging Table Though Scripted RestApi</title>
      <link>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884309#M456088</link>
      <description>&lt;P&gt;Hi Ankur,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for joining, yup i now that that need to&amp;nbsp; inform 3rd party to change the endpoint but as i am new Scripted RestAPi so i need help on how to bulid logic in script section.&lt;/P&gt;
&lt;P&gt;Suppose my Staging Table is CMDB_TEST now what logic i need to write in script section.Please help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;Yad&lt;/P&gt;</description>
      <pubDate>Fri, 15 May 2020 10:00:14 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884309#M456088</guid>
      <dc:creator>yadi</dc:creator>
      <dc:date>2020-05-15T10:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk Upload in Staging Table Though Scripted RestApi</title>
      <link>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884310#M456089</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;create new scripted rest api and new scripted rest resource&lt;/P&gt;
&lt;P&gt;Rest Resource -&amp;gt; POST Method&lt;/P&gt;
&lt;P&gt;Script below:&lt;/P&gt;
&lt;P&gt;1) iterate over the body&lt;/P&gt;
&lt;P&gt;2) parse the json&lt;/P&gt;
&lt;P&gt;3) for every object from the array&lt;/P&gt;
&lt;P&gt;Sample below: Ensure you are receiving the above json request; I have assumed the json key is the column name&lt;/P&gt;
&lt;P&gt;Also use proper import set table in GlideRecord&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
	
	var requestBody = request.body.dataString;
	var parser = new global.JSON();
	var parsedData = parser.decode(requestBody);
	
	for(var i=0;i&amp;lt;parsedData.length;i++){
		
		
		var gr = new GlideRecord('cmdb_test');
		gr.initialize();
		gr.u_displayname = parsedData[i].u_displayname;
		gr.u_vendor = parsedData[i].u_vendor;
		gr.u_primaryipv4address = parsedData[i].u_primaryipv4address;
		gr.u_primaryosversion = parsedData[i].u_primaryosversion;
		gr.u_primaryostype = parsedData[i].u_primaryostype;
		gr.u_osdescription = parsedData[i].u_osdescription;
		gr.u_physserialnumber = parsedData[i].u_physserialnumber;
		gr.u_primarydnsname = parsedData[i].u_primarydnsname;
		gr.insert();	
	}	
	var responseBody = {};
	responseBody.status = "Success";
	response.setBody(responseBody);
	
	
})(request, response);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Mark &lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; Correct if this solves your issue and also mark &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt; Helpful if you find my response worthy based on the impact.&lt;BR /&gt;Thanks&lt;BR /&gt;Ankur&lt;/P&gt;</description>
      <pubDate>Fri, 15 May 2020 10:15:33 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884310#M456089</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2020-05-15T10:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk Upload in Staging Table Though Scripted RestApi</title>
      <link>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884311#M456090</link>
      <description>&lt;P&gt;Thanks Ankur let me try this logic and get back to you.&lt;/P&gt;</description>
      <pubDate>Fri, 15 May 2020 10:31:55 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884311#M456090</guid>
      <dc:creator>yadi</dc:creator>
      <dc:date>2020-05-15T10:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk Upload in Staging Table Though Scripted RestApi</title>
      <link>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884312#M456091</link>
      <description>&lt;P&gt;Sure,&lt;/P&gt;
&lt;P&gt;Do let me know;&lt;/P&gt;
&lt;P&gt;If that helped Kindly close the thread by marking Answer as &lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; Correct &amp;amp; &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;Helpful so that it does not appear in unanswered list.&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Ankur&lt;/P&gt;</description>
      <pubDate>Fri, 15 May 2020 10:34:07 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884312#M456091</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2020-05-15T10:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk Upload in Staging Table Though Scripted RestApi</title>
      <link>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884313#M456092</link>
      <description>&lt;P&gt;Hi &lt;SN-MENTION class="sn-mention" table="live_profile" sysid="19525629dbd81fc09c9ffb651f961989"&gt;@Ankur Bawiskar&lt;/SN-MENTION&gt;, thanks for your help on the above, we have build something very similar starting from your code, however we have a performance related query.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When we use this method of inserting each record into the staging table, as soon as that record is inserted, it will trigger the transform map immediately just for that one single record.&lt;/P&gt;
&lt;P&gt;So to illustrate this, lets say we receive a&amp;nbsp;JSON payload containing 10k records from ThirdParty, our scripted REST API will parse and insert each record sequentially into the staging table. That ultimately means that the transform map will be triggered 10k times (we can see this in the transform history).&lt;/P&gt;
&lt;P&gt;The issue is we have an integration where we are expected to receive payloads of up to 60k-100k records at a time, and it takes a couple of hours to process this because of the single record process/transform. Alternatively if we load the data manually via a DataSource(excel file), it only runs the transform map ONCE, and the execution time is 15-20 minutes.&lt;/P&gt;
&lt;P&gt;Can you (or someone) please suggest a way in which we can insert all the records(similar to excel DataSource) into the staging table before it starts&amp;nbsp;transforming&amp;nbsp;each one individually?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope the attached image of a POC on my dev instance can help with visualizing the issue.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="find_real_file.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/92949i1D64487312A94989/image-size/large?v=v2&amp;amp;px=999" role="button" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 16:32:35 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884313#M456092</guid>
      <dc:creator>Alex Perju</dc:creator>
      <dc:date>2021-07-28T16:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk Upload in Staging Table Though Scripted RestApi</title>
      <link>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884314#M456093</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Not very much sure. but you can try to create data source, create csv file with all those records and attach to data source and then trigger the transform&lt;/P&gt;
&lt;P&gt;So it would run for all records at once&lt;/P&gt;
&lt;P&gt;Regards&lt;BR /&gt;Ankur&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 05:25:08 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884314#M456093</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2021-07-29T05:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk Upload in Staging Table Though Scripted RestApi</title>
      <link>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884315#M456094</link>
      <description>&lt;P&gt;Thank you &lt;SN-MENTION class="sn-mention" table="live_profile" sysid="19525629dbd81fc09c9ffb651f961989"&gt;@Ankur Bawiskar&lt;/SN-MENTION&gt;&amp;nbsp;, do you know if there is a ServiceNow API that we can use to transform our REST payload from JSON into an EXCEL file or DataSource?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 08:42:02 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884315#M456094</guid>
      <dc:creator>Alex Perju</dc:creator>
      <dc:date>2021-07-29T08:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk Upload in Staging Table Though Scripted RestApi</title>
      <link>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884316#M456095</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;check this&lt;/P&gt;
&lt;P&gt;&lt;A href="https://developer.servicenow.com/dev.do#!/reference/api/orlando/server/no-namespace/GlideImportSetTransformerAPI" target="_blank"&gt;GlideImportSetTransformer - Scoped, Global&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.servicenow.com/community?id=community_question&amp;amp;sys_id=16d197addbdcdbc01dcaf3231f9619be" target="_blank"&gt;REST Import set mode&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Regards&lt;BR /&gt;Ankur&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 10:07:44 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/bulk-upload-in-staging-table-though-scripted-restapi/m-p/884316#M456095</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2021-07-29T10:07:44Z</dc:date>
    </item>
  </channel>
</rss>

