Exporting large custom applications - A workaround
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
As I struggled to find any mentions of similar situations on the internet, and since found a solution I thought I'd share it with the community.
Some context
We work at a client which has on-premise instances with no internet access. We are building a custom application for them and need to transfer this app to various different on-site locations, so our app needed to be exported.
The app that we've built is large (currently +75MB), which was difficulty to export as a whole in an update set (server timeouts would prevent exporting to XML, since the gateway timeout was reached before the XML file was ready).
The solution
We published the app to an update set, after which we wanted to download the entire app. This is when we ran into issues. The Export to XML action is waits for the server to respond with the redirect URL, which takes too long.
The Export to XML UI Action triggers a backend process that creates and formats the XML download; which still works well, even with custom applications of this size. Our issue is related to a front-end gateway server timeout, so we needed to create a workaround that doesn't redirect, but gives the user the redirect url in an async(ish) manner.
Adding the gs.info() method with the URL allows you to download the file after the process has completed, without the redirect.
var updateSetExport = new UpdateSetExport();
var sysid = updateSetExport.exportUpdateSet(current);
action.setRedirectURL("export_update_set.do?sysparm_sys_id=" + sysid + "&sysparm_delete_when_done=true&sysparm_is_remote=false&sysparm_ck=" + gs.getSessionToken());
gs.info("Download URL: https://{INSTANCE URL}/export_update_set.do?sysparm_sys_id=" + sysid + "&sysparm_delete_when_done=true&sysparm_is_remote=false&sysparm_ck=" + gs.getSessionToken());
Which results in the following log message, which can be put into the URL after which the updateset will download:
Note that if your file downloads, the file will be removed after downloading so using the URL after will not work due to the sysparm_delete_when_done=true.
Struggles
Our initial workaround was to use a scheduled script so that it would be run in the backend, but this resulted in some strange behavior where all customer updates were included in the XML; resulting in XML files 2GB+
After testing this was the most functional solution.
Please note this was a last resort solution, and I do not recommend changing OOTB ServiceNow UI Actions; but if you have no choice, then this might be an option.
Cheers!