How do you include "Script Includes" in a workflow script?

santrym
Mega Expert

I have a script in my workflow that I want to make globally usable by other workflows. So, I added the script contents to the "Script Includes" table. Now I want to replace the script from the workflow with the newly created "Script Include", lets call it "global script". How do I replace the contents of my workflow's script and replace it with an include/call to "global script"?

Does this make sense. Any help or thoughts are appreciated!

1 ACCEPTED SOLUTION

Ken83
Mega Guru

From your workflow, I'm assuming you're using a "Run Script" activity, you need to initialize your script include that you created. Like so...



var scriptInclude = new scriptIncludeNameGoesHere();



Now that you've initialized your script include, you need to determine what function/method you want to trigger within the script include. It would look something like this..



var trigger = scriptInclude.functionNameGoesHere(//insert parameters here if you need to. If there aren't any, leave the parenthesis empty);



This line will trigger the method within your script include where you've moved your functionality and in your workflow, now you'd only have 2 lines of code and the Server side would be doing all of the lifting.


View solution in original post

6 REPLIES 6

Ken83
Mega Guru

From your workflow, I'm assuming you're using a "Run Script" activity, you need to initialize your script include that you created. Like so...



var scriptInclude = new scriptIncludeNameGoesHere();



Now that you've initialized your script include, you need to determine what function/method you want to trigger within the script include. It would look something like this..



var trigger = scriptInclude.functionNameGoesHere(//insert parameters here if you need to. If there aren't any, leave the parenthesis empty);



This line will trigger the method within your script include where you've moved your functionality and in your workflow, now you'd only have 2 lines of code and the Server side would be doing all of the lifting.


Thank you! I guess I was thinking the include looked different. I was looking for, as is found in some programming languages, an "import" or "include" key word. Thank you for your help!


Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Michael,



This wiki article describes how to call a script include from a server side script. You should be able to call it from anywhere in a workflow script the same way you can call it from a business rule or any other server side scripting area.


Shawn Dowler
Tera Guru

If you haven't got this working yet, it might be helpful for you to post the contents of the script include that you created to ensure that you have the functionality encapsulated in one or more functions that you can call from another server side script.