Process XML Import via Script?

pfeifn
Kilo Expert

Is there an out of box way to process an XML import file via script rather than GUI? ( instead of going to "Import XML" have a script that pulls the file by location or content and processes it? )

Thanks!

1 ACCEPTED SOLUTION

No good global solution was found unfortunately. You could probably get away with doing it for 1 or a handful of tables if you are really careful, but it is probably not worth it in that regard. 

I checked with SN and they said the actual import process cannot be called via script. Disappointing, hopefully one day "releases" into service-now will be able to be automated! 

View solution in original post

9 REPLIES 9

I don't think that the Import Set API is going to solve this requirement.   Imagine importing a group via XML.   The sys_id for the group will be preserved.   However when transforming via an import set you could create a new group, but the sys_id would be the same.   Thus, this API isn't really a way to script a manual XML import.  Please correct me if I'm thinking of this wrong.

pfeifn
Kilo Expert

Thanks Sachin and Michael, I will try out the Rest API this week(hopefully)!

No good global solution was found unfortunately. You could probably get away with doing it for 1 or a handful of tables if you are really careful, but it is probably not worth it in that regard. 

I checked with SN and they said the actual import process cannot be called via script. Disappointing, hopefully one day "releases" into service-now will be able to be automated! 

yair_leibkowiz
ServiceNow Employee
ServiceNow Employee

well, there is a way to do it by using the attached tool.

you can import the attached scripts to your instance, check the readme.

the way it works: you need to create your JSON with the records you want to export and run this tool.

the tool creates an update set with the files you mention. you can import them as an update set in other instances as well. 

Rich_Art
Tera Contributor

Hi Pfeifn,

 

This is possible by using the GlideUpdateManager2. You can simulate an XML to be loaded as if it came from an update set by using the loadXML function:

 

var xml = '<record_update sys_domain="global" table="cmdb_ci"><cmdb_ci action="INSERT_OR_UPDATE">...</cmdb_ci></record_update>'; //provide your full xml (or get it from an attachment)

var um = new GlideUpdateManager2();
um.loadXML(xml); //load that xml