UI Policy not working after migrating catalog item workflow to Flow

SumajRajNk
Tera Contributor

Hi Everyone,

We have been using the below script in UI Policy to make the task resolver input visible and mandatory. It is working fine for workflow but after migrating to Flow this UI Policy is not working. As my understanding the 'wf_activity' will not work in Flow. Is there any other replacements or any script modification that I can do to achieve the same through script itself.  Please suggest me if you have any idea to solve this.

 

function onCondition() {
    if(g_scratchpad.wf_activity == 'Task 2'){
        g_form.setVisible('hidden_SERBuild_please_provide_the_firewall_requirement_and_patrol_agent_details',true);
     g_form.setMandatory('hidden_SERBuild_please_provide_the_firewall_requirement_and_patrol_agent_details',true);
    }
}
2 REPLIES 2

RobCook86
Tera Expert

wf.activity wont work on flows so you need to pass the values another way. You can pass the values into the scratchpad with a BR so you can call this from your UI Policy by doing the following:

 

Use Flow Designer to set a field like current_step = "Task 2"

 

Then create a BR to set the value to the scratchpad

 

g_scratchpad.flow_step = current.current_flow_step;

 

Then call the scratchpad value from the UI Policy

function onCondition() {
    if (g_scratchpad.flow_step == 'Task 2') {
        g_form.setVisible('hidden_SERBuild_please_provide_the_firewall_requirement_and_patrol_agent_details', true);
        g_form.setMandatory('hidden_SERBuild_please_provide_the_firewall_requirement_and_patrol_agent_details', true);
    }
}

 

Cheikh Ahmadou
Tera Guru

The problem is that your UI Policy script:

if (g_scratchpad.wf_activity == 'Task 2') {
...
}


no longer works after migrating from Workflow to Flow Designer, because g_scratchpad.wf_activity is not populated.

Solution:

You must have some field or logic that tells you what "task step" you're in for example:

  • current.stage

  • current.state

  • A custom field like current.u_current_step

So add a UI script or a UI Policy to update scratchpad with a new variable for example flow_step  and set it.
Then update your script to: 

function onCondition() {
  if (g_scratchpad.flow_step == 'whatever the step should be') {
    g_form.setVisible('hidden_SERBuild_please_provide_the_firewall_requirement_and_patrol_agent_details', true);
    g_form.setMandatory('hidden_SERBuild_please_provide_the_firewall_requirement_and_patrol_agent_details', true);
  }
}


This approach works both in classic UI and Service Portal, as long as you define what "step" you're on during Flow execution.