Export to MID server from script

teroruuskanen
Giga Contributor

Greetings,

Is it possible to export data to MID server from script? It's possible with export sets, but I would like to create a form to our Service Portal and on submit save the form data to a table as well as export the data to a location on our mid server.

Thank you.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Tero,



As of now Servicenow provides that functionality through export set and you need not write any script.



To achieve your requirement:


1) Create custom table to hold the values user submits


2) Create export definition, export target, export set and scheduled export mention file name etc, csv format etc


3) Scheduled export will be active false since you will be triggering it via script


4) Have after insert business rule on your custom table to trigger the scheduled export



script below:



var gr = new GlideRecord("scheduled_data_export");


gr.addQuery("sys_id", ''); // sys_id of your scheduled export


gr.query();


if (gr.next()) {


gs.executeNow(gr); // if using in scoped app



SncTriggerSynchronizer.executeNow(gr); // if using in non-scope app i.e global


}




Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

View solution in original post

3 REPLIES 3

shanjith
Mega Guru

Hi Tero,


        you want to get data from MID server or send data to mid server?



Thanks,


shanjith joy




PS: Hit like, Helpful or Correct depending on the impact of the response


I want to export data TO mid server as I wrote in the original post.


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Tero,



As of now Servicenow provides that functionality through export set and you need not write any script.



To achieve your requirement:


1) Create custom table to hold the values user submits


2) Create export definition, export target, export set and scheduled export mention file name etc, csv format etc


3) Scheduled export will be active false since you will be triggering it via script


4) Have after insert business rule on your custom table to trigger the scheduled export



script below:



var gr = new GlideRecord("scheduled_data_export");


gr.addQuery("sys_id", ''); // sys_id of your scheduled export


gr.query();


if (gr.next()) {


gs.executeNow(gr); // if using in scoped app



SncTriggerSynchronizer.executeNow(gr); // if using in non-scope app i.e global


}




Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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