The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

Brian Lancaster
Giga Sage
Giga Sage

When does the client script run?  Is there a field that is unique to these task that your can use to determine that it need to run on this task?

Nope. Another requirement is all variables are shown on all tasks. There is nothing other than unique text identifiers to tell me what the differences are.

 

Any ideas?

ccajohnson
Kilo Sage

What are you needing to do within the Catalog task record? Knowing this may help us to narrow our solutions we present. If you need to determine exactly which Catalog Task record to act upon, you may want to consider leveraging the Workflow activity [wf_activity] field.

I have done something whereby during a specific task, certain variables become mandatory when that Catalog task becomes closed. For all other tasks whereby the variable is on the task, it is not changed. Let us know if this is a possible solution and I will share what I have done.

Yes the case you described could be like one case. In my case I want to display an info message when the task is the correct one.