Error compiling a flow that calls a subflow which are both part of an application that has been developed, uninstalled, and reinstalled on the same instance


Description

If an application contains a flow and a subflow and the flow calls the subflow, the flow may fail to compile and run after the application is uninstalled and reinstalled on the same instance where the flow was developed and tested. This occurs because the latest snapshot of the subflow will become corrupted when the application is uninstalled and that corrupted snapshot will be referenced by the subflow definition when it the application is reinstalled.

Steps to Reproduce

1. Create an application in app studio.
2. Add a subflow and a flow that calls that subflow to the application.
3. Run the flow and verify that the sys_hub_flow_snapshot table now has a row for the subflow. verify that the parent_flow field points to the sys_hub_flow record for the subflow.
4. Commit the application to github.
5. Uninstall the application.
6. Look at the subflow's sys_hub_flow_snapshot record and notice the parent_flow field is now null and the sys_hub_flow record for the subflow is deleted from the isntance.
7. Reinstall the application.
8. Look at the subflow's sys_hub_flow_snapshot record and notice the parent_flow field is stilil null and the sys_hub_flow record for the subflow has now been reinserted on the instance.
9. Go to the flow in flow designer and click test. This causes "Internal Server Error" / "Could not retrieve snapshot".

Workaround

This problem has been fixed. If you are able to upgrade, review the Fixed In section to determine the latest version with a permanent fix your instance can be upgraded to.

The workaround is to force all flow, subflows, and actions in your store application to recompile using this below script. This will dissociate the sys_hub_flow record from the corrupted sys_hub_flow_snapshot records. The snapshots will automatically be recompiled and persist correctly for the next runs.

In the workaround script below, replace "[YOUR SYS_STORE_APP ID HERE]" with your sys_store_app.sys_id before running:

function forceRecompile(tableName) { 

   gr = new GlideRecord(tableName); 
   // only include records belonging to your store application
   gr.addEncodedQuery('sys_package=[YOUR SYS_STORE_APP ID HERE]'); //to be replaced with your sys_store_app.sys_id
   gr.query(); 
   while (gr.next()) { 
      if (JSUtil.nil(gr.getValue("master_snapshot"))) //will not impact Kingston action/flows with no main snapshot
         continue; 
      gr.setValue("latest_snapshot", gr.getValue("master_snapshot"));  
      gr.setWorkflow(false); //to not go in updateSets
      gr.update(); 
   } 

forceRecompile("sys_hub_action_type_definition"); 
forceRecompile("sys_hub_flow"); 


Related Problem: PRB1473635