Is there a way to easily package an "install script" which should run once to deploy some functionality?

Tim Woodruff
Mega Guru

I have a script that I want to run.

This script deploys some functionality. It is effectively an "install script",

but it's a little bit metamorphic because it customizes the install to the user's instance and usage.

It's about a thousand lines, but it installs something closer to like 100k lines (intelligently; not haphazardly), so obviously the usual methods of installing an app or loading an update set aren't... at least as far as I know... a viable option.

Let's say it's: "doInstall();"

Is there any way to package this script in such a way, that I can easily deploy it into an instance? Something like an update set that would deploy and then execute (only once) a script include?

I can put it into an update set as a script include, but I'm not sure how to actually invoke the script to do the install.

Any pro-tips for me?

EDIT: Whether it's a pre-packaged "install script" or some way to simply execute a script after installing an update set, it would be useful to know how to do this.

I have tried adding a scheduled script execution to an update set, then manipulating the update set XML so that its' "run_start" value is "javascript:gs.minutesAgo(-3)", but that doesn't seem to work. It doesn't accept that value.

Perhaps there's some way to execute a script inside of an update set prior to deploying it?

Anything like that, or any point in the right direction would be extremely useful.

Message was edited by: Timothy Woodruff

1 ACCEPTED SOLUTION

Tim Woodruff
Mega Guru

In case anyone happens across this article, I found a way to do it. I packaged it into this app: SN Pro Tips — Update Set Collision Avoidance


You can download that to see how it works, in case you need an example to work off of.  


View solution in original post

9 REPLIES 9

ghsrikanth
Tera Guru

Yes, there is a concept called Fix Scripts in Servicenow, those scripts can be made to run once after upgrade or cloning -


For more information, refer the below wiki article -


Fix Scripts - ServiceNow Wiki


Run onceSelect the check box to run the script only one time (default). The fix script is ignored for subsequent upgrades.

Clear the check box allow the script to run every time the application is installed or upgraded.


This option is enforced by the following mechanism.


  • When a fix script is processed, a corresponding record is added to the sys_update table.
  • The upgrade process automatically skips fix scripts that are flagged as Run once and have an entry in the sys_update table.

Run once is not enforced when you test the fix script.



Screen Shot 2016-03-19 at 10.23.18 AM.png



Mark if it is helpful or correct, feedback is appreciated


So would you say I'd just install an application where the only thing in it is this fix script?


Would the code have the same limitations as scoped apps?


(I've never built an app before except through the developer site tutorial)


ghsrikanth
Tera Guru

Yes, if the new application is built in its own scope, then there will be restriction in accessing the tables belonging to other applications in different scope.


Make sure the tables what you will be accessing in the fix script will have property enabled in their table configuration tab in such a way, the application belonging to other scope can access it



Hopefully it helps


Thanks Srikanth; however, this is exactly one of the things that I want to avoid. My script needs to run in the global scope. Are you aware of anything that would make that possible?