Recursive Scripting in ServiceNow

tahnalos
Kilo Sage

I'm trying to ascertain the feasibility of a recursive code script.

Long story short, we are trying to link dependant tickets together using a single reference field on the Task form.  We link a task as "dependant" if we require actions from that Task to be completed first.  But it's also possible that the "dependant task" itself also has a dependancy.

The idea that I have is to have a script include look at the dependant task, then call itself again to look at further dependancies, thus trying to determine how far the level of dependency tasks go.  This would link into other functionality that we have in the works, but a ServiceNow rep has suggested that the code may be flagged as "problematic" by ServiceNow itself, considering that this may result in a long running time depending on how deep the dependant tasks go.  Business has suggested that with current practices, this should go no longer than 5-deep, but the ServiceNow rep is insistent that we abandon that approach.

Can someone tell me how a recursive script can be labelled as "problematic"?  It isn't the same as a recursive business rule which does a current.update () on a before rule, so I'm not sure how the dependency search would be an issue.  Or does anyone else have an alternative as to what I am trying to do?

Thanks

9 REPLIES 9

Yes, but the recursive script has a condition which terminates if it cannot find a dependant task.  So honestly this shouldn't result in long running time, but ServiceNow says that this kind of code will automatically be flagged for remedial action.  You would think their health check tools could find if there is a terminating condition for such recursive coding.

I think there are to many ways to go about it and its just easier to just flag it so someone manually reviews it.

We just ignore there call out of it.

Easy for you.  The rep who is assigned to us is insistent that the code not be used as it will affect our "support contract".

I would ask him/her if he is a developer and if he is then for him/her to tell you how to get it done without impacting the support contract.  If he/she is not then I would tell him/her that they need to provide free consulting services so that a solution to the issue can be built that will not impact the support contract.

The system has protections against infinite loops and in my opinion they have no right to tell you that you cannot do something some way without providing an alternative.  Otherwise whats the use in there product if you cannot use it to provide solutions for business needs.

 

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Recursive scripts can certainly cause issues if not done correctly.  Good news though is the platform has protection in place via transaction quotas to ensure something just doesn't run forever.  I learned quite about about recursive scripting by reading this very old article on SN Guru:

https://www.servicenowguru.com/scripting/script-includes-scripting/advanced-getmygroups-function/

 

Basically this script recursively navigates group hierarchy and gathers a list of groups or members.  The nice thing about this example is it has protections built in where you can tell it to only go X levels deep, so you can use this as an example.