Best Practices for Testing Workflow Activity

mmujica
Kilo Contributor

I am using Run Script activities in my workflow to handle some complex logic (mainly data twisting and Rest calls, which are easier to debug in script than using Rest Message activity).

My development workflow is a bit painful, since I have to make changes, save them, then start the workflow from the UI. Then I have to look through the Workflow active contexts logs, most of which aren't relevant to me. What's the best way to test these scripts in isolation? Ideally I could set up a current object and scratchpad, and then click a button to run the script.

I could set it up outside SNOW, but I'd have to mock out all the APIs (eg GlideRecord, RESTMessageV2). And if my bug is in misusing the APIs, that type of test won't catch it.

3 REPLIES 3

dvp
Mega Sage
Mega Sage

Did you try Scripts - Background ?


HugoFirst
Kilo Sage

Did you try testing it as a business rule in the scheduled jobs module?


That works for me for a wide variety of server side scripts.



Here's 2 links for business rule best practices:


Debugging Business Rules - ServiceNow Wiki  



Debugging Tools Best Practices - ServiceNow Wiki  


  1. I put my nasty scripts in a Script Include, lets say Scrobulator.
  2. I make a properties page that has some sort of "enable debug" property, perhaps just the debug level.
  3. I add a UI Action on the appropriate object, maybe "Test the Scrobulator."
  4. I add breakpoints to my nasty script.
  5. I enable the Script Debugger
  6. I select the appropriate record and then the UI Action.
  7. I hit the breakpoint.
  8. I step until I hit a problem.
  9. I loop back to 6 until I'm done.