The CreatorCon Call for Content is officially open! Get started here.

sabell2012
Mega Sage
Mega Sage

NOTE: ON APRIL 1, 2016 ACCENTURE COMPLETED THE ACQUISITION PROCESS OF CLOUDSHERPAS.   AT THAT TIME THE CLOUDSHERPAS BLOG SITES WERE DOWNED FOREVER.

THIS IS THE RE-PUBLICATION OF MY ARTICLE FROM June 2, 2015 ON THE CLOUDSHERPAS SERVICENOW SCRIPTING 101 BLOG.

____________________________________________________________________________

While working with several clients on various Orchestration projects, it became abundantly clear that there are certain methodologies that should always be included on these type of projects.   We were seeing far too many instances with poor workflow structuring techniques, no coding standards, inefficient code and designs, inconsistent workflow planning and a lack of reusability!   So, with those in mind, here are some best practices for Orchestration in ServiceNow that can help you avoid common mistakes and challenges.


General Best Practices

These best practices are meant for Orchestration projects, but you can also apply them to workflows:

  1. Use system properties to configure the workflow. If you have a constant in your script, move it to a system property. Benefits include the ability to make on-the-fly changes without the need to check out the workflow and the ability to store the value in a format other than plain text.

  1. Remove workflow input variables prior to going to production. Use workflow.scratchpad or system properties and be sure to use input variables for unit testing purposes only.

  1. Adhere to the following testing progression process:

a. Use input variables as initial feeds

b. Then use the current object, but without a call out to powershell scripts

c. Then use the current object with a call out to powershell scripts and verify that the values are making it (use the Write-Host commandlet, as it will then be returned in the XML and fed back to the ECC queue).

  1. Consider using a primary workflow and then building out sub-workflows for each task grouping. This allows you to "build" upon existing functionality and reduces workflow complexity.



Coding Best Practices

  1. Use a Run Script Activity at the beginning of the workflow to initialize your workflow scratchpad variables (including system property gets) to be used downstream.

  1. Create a library of functions using a Script Include(s) for reuse.

  1. Use code to call Script Includes to retrieve data, operate on data or where involved processing needs to occur.

  1. Use a Set Values Activity or Run Script to update the current object. If a Run Script is used, do NOT use current.update()!  

  1. Try to set up return information with your custom powershell scripts to get any feedback or error information back into the stream. Write this information down in the system logs. Remember to handle your errors!

  1. When logging using gs.log(), make certain you use the second parameter ability to record where the gs.log was actually fired! This will help you track down mystery error messages appearing in your logs. Failure to do this could cause you a couple of hours tracking down the gs.log location in your workflow code! Remember: Activity scripts are NOT searchable!

a. example: gs.log('---> ERROR! ' + err, 'WF:<<workflow name and activity>>'); // Not scope safe in Fuji+

b. example: gs.info('---> {1}, ERROR! {0}', err, 'WF:<<workflow name and activity>>');   // Scope safe in Fuji+

  1. Use JSUtil.nil()/.notNil() <string>.nil() in condition statements. Note: JSUtil is currently not scope safe in Fuji+.

  1. When converting a value to a String, use + "" or .getValue(<field>), but remember that getValue() cannot dot-walk!

  1. If you need workflow debugging, set the system property glide.workflow.log.debug to true and use workflow.debug during testing.

  1. If you're using powershell, consider writing your own MID Server script files.

  1. Comment your code!!!


Final Tips for Orchestration Success

To finish off, remember to keep things simple and straight-forward when you're creating an Orchestration workflow and code. Comments and standards keep the number of hours spent in maintenance to a minimum. Last but not least, the following points should be chiseled in stone for you:

  1. Consistency of the workflow, coding best practices and variable usage are the key to reusable and maintainable code!

  1. Your changes to a workflow are not placed into the current update set until you publish.

Learn More

For more information on using Orchestration in ServiceNow, check out these Wiki articles:

And be sure to watch this replay of our recent webinar on how to optimize your service automation processes with ServiceNow Orchestration.


mamann also contributed to this post.

Steven Bell

If you find this article helps you, don't forget to log in and "like" it!

Also, if you are not already, I would like to encourage you to become a member of our blog!

accenture technology logo.pngsn-community-mvp.png

3 Comments