Catalog task activity in workflow editor is opening very slowly


Description

When we open any catalog task activity in workflows or drag it to the workflow, it is taking more than 5 mins to open the activity or browser is getting crashed.

Cause

On the catalog item activity, there is a field called "Variables on task Form" which will bring all the variables based on the business rule: Workflow Item Variables.
It is running the function wf_variables() and trying to load the variables from item_option_new table based on addDefaultVariables function since the workflow is not a part of any item, it is loading all the variables.

The problem is the fact that we're loading the entire item_option_new table on the form under the Variable on Task Form via business rule "Workflow Item Variables":

//no items have workflows, default to all variables
function addDefaultVariables(variables) {
var itemVars = new GlideRecord('item_option_new');
itemVars.addNotNullQuery('name');
itemVars.query();

The server-side transaction finishes within 16s. The client-side (the browser) on the other hand takes another 90s to just build that slush bucket.
There is nothing we can do to improve the performance here as it's client-side not platform side.

Since there are 50000+ records in item_option_new, it is by default as per logic in the business rule "Workflow Item Variables" loading all the variables in the slush bucket.

Resolution

Attach the workflow to any item so it will only load variables part of that catalog item which will resolve the issue. For the newly created workflow as well, once you create the workflow, before adding the catalog task activity, publish the workflow and then add the same to catalog item and then add the catalog task activity in the workflow which will resolve the issue.