Run catalog client scripts on certain tasks in workflow without using short_description

PranavSuj96
Mega Expert

Hey all,

 

I have a requirement where I need to use catalog client scripts to act on certain workflows. Up until now I always used g_form.getValue('short_description') to check for a matching short description before any actions were taken. 

 

However, during code review today it was requested that no hard coded values are used. Is there a way that I can make a catalog client script work on a specific task without checking its description?

 

Thanks,

Pranav

1 ACCEPTED SOLUTION

You can capture the Workflow activity [wf_activity] reference field value by setting a g_scratchpad variable that can be leveraged client-side:

Depending upon how you want to leverage the g_scratchpad variable, you can use UI Policies (not, Catalog UI Policies) to do this. For this example, I am going to have a variable called sample_variable become mandatory for the Workflow Activity that is named "Sample Task".

1. Create a Business rule that captures the wf_activity name:
Name: Set g_scratchpad for sc_task
Table: Catalog Task [sc_task]
Advanced: true
When: Display
Script:

(function executeRule(current, previous /*null when async*/) {
    g_scratchpad.wf_activity = current.wf_activity.getDisplayValue();
})(current, previous);

2. Create a UI Policy on the Catalog Task table that makes the variable mandatory when closing:

Make Variables Mandatory on Close
Table: Catalog Task [sc_task]
Reverse if false: true
Order: 300
Global: true
Short description: FP - Make Variables Mandatory on Close
Conditions:
State | is | Closed Complete
Run scripts: true
Execute if True:

function onCondition() {
    if (g_scratchpad.wf_activity == 'Sample Task') {
        g_form.setMandatory('variables.sample_variable', true);
    }
}

Execute if False:

function onCondition() {
    g_form.setMandatory('variables.sample_variable', false);
}

3. Change the existing UI Action used to close the task to include the logic to make the variable mandatory:

Close Task
Name: Close Task
Table: Catalog Task [sc_task]
Order: 100
Action name: close_task
Client: true
Onclick: closeTaskCheck();
Script:

function closeTaskCheck() {
    if (g_scratchpad.wf_activity == 'Sample Task') {
        g_form.setMandatory('variables.sample_variable', true);
    }

    gsftSubmit(null, g_form.getFormElement(), 'close_task');
}
if (typeof window == 'undefined') serverCloseTask();

function serverCloseTask() {
    current.state = 3;
    current.update();
}

Let us know if there are any other scenarios that could be covered by this technique.

View solution in original post

10 REPLIES 10

Nevermind I figured it out.