Part 1: Making a Marvel Snap Clone in ServiceNow

Marvel Snap Review - IGN

Iโ€™ve been asked to talk at a ServiceNow User Group about Flow Designer so Iโ€™ve had a bit of a think about what sort of Flow Designer topics might be interesting. ย 

Something I try to do every time I create a system is look at ways to make it extensible from the get-go. ย With any sort of solution youโ€™ll often be asked to meet a particular business need or process, but you can almost guarantee that most processes you might create are going to either change or have variations or โ€œwhat ifโ€ scenarios. ย 

One of the principles I try to keep in mind with Flow Designer is โ€œSubflows firstโ€ – meaning that when I think about a โ€œthingโ€ I might need to do, I will try to build the smallest part of the logic first and THEN wrap it in a trigger. ย Quite often when I use Flow Designer my actual Flows are very very lightweight – in many cases the Flows will just be a trigger that passes the attributes of the trigger (the record object for example) immediately to a Subflow. ย  I try not to overload my flows with too much logic and let my Subflows do the work.

Another principle I stick to is whenever thereโ€™s any sort of decision I try to make it data driven. ย One of my favourite features of ServiceNow is the Decision Table/Decision Builder system. ย Itโ€™s a great way of making sure that any โ€œif / elseโ€ logic is stored in a decision table that can be modified easily in data rather than by modifying the structure of the flow. ย When you use Decision Tables in concert with another little-known feature of Flow Designer called Dynamic Subflowsย you get this really powerful combination where you can create a Flow system that is very flexible and future proofed against increasingly complex process behaviours.

For example I might have a process that is initially based on the fact that I have three different customers, and each has a slightly different process. ย In a simplistic world I might have written a Flow that has a hard-coded IF block that triggers one of 3 different subflows depending on the customer selected. ย In future when I get a fourth customer, maybe Iโ€™d add the fourth Subflow, and modify my flow trigger to have fourth option. ย 

However as this starts to scale it gets more complex. ย Lets say I have a dozen customers and half of them have unique processes, but the rest are happy to use similar processes to other teams. ย At this point my If block in the flow is going to become more complex – customer A, B and C all use subflow X, Customer D uses Subflow Y, Customers E and F use Subflow Z, etc.

This is where Dynamic Subflows come in – this is a flow action that allows you to call a subflowย pattern and pass a data pill that contains the name of the specific Subflow from that subflow pattern you want to call. ย So instead of having an If block outcome for each Subflow call that has the Subflow calledย specifically you can instead have a single action that calls a subflow that your flow logic has determined by name.

You can see how this might be benficial if you can use some form of logic to determine what subflow name you wanted to call. ย How can we get names dynamically? ย Well, thatโ€™s where Decision Tables come in! ย A decision table is basically a collection of conditions based on a set of inputs that will give you an output. ย For example you might send your โ€œcompanyโ€ value to a Decision Table that youโ€™ve set up, and you would have one or more decisions that have conditions based on the company input. ย The output can be any record in the system (for example a Subflow recordโ€ฆ.). ย Thereforem ย My condition might be โ€œCompany = Company Aโ€ and it might have an output of โ€œSubflow Xโ€. ย My conditions can even be complex – “Company = Company A OR Company B OR Company C” and the output might still be Subflow Xโ€. ย 

Decision Table logic all takes place outside Flow Designer – this complex decision logic can be completely removed from my flow and the logic ends up being just 2 actions instead of dozens of actions. ย By sending the output of the Decision (e.g. the Subflow record) then my Dynamic Subflow action can simply receive the name of the chosen Subflow and it will execute whatever logic is required based on the common inputs from my main Flow.

In order to demonstrate this for the SNUG Iโ€™m going to be creating a clone of the Mobile Game Marvel Snap. ย Marvel Snap is a good use-case for Dynamic Subflows because each card you can play has a unique behaviour that needs to be executed. ย These can all be defined as Subflows for each card, and the underlying flow can determine when the card logic should be called (using Decision Tables based on the fundamental execution order rules of the game), and which card rule should be executed (using Dynamic Subflows). ย ย 

Iโ€™ve found an API where I can import all the cards into my instance into my Card Database, but Iโ€™ll still need to create all the Card Subflows one by one. ย Iโ€™m wondering whether thereโ€™s a way to use ServiceNowโ€™s Generative AI to help interpret the card description within the context of my system, but I suspect that might not be as easily done as I suspect. ย Weโ€™ll see how far I can get! ย ย 

Iโ€™ll be pushing all my updates to the app to my GitHub Repo where Iโ€™m calling it โ€œMarvel SN App”, so if youโ€™re interested you can grab a copy or maybe even suggest some improvements:ย  https://github.com/milligna/Marvel-SN-App


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *