How to make a catalog item variable mandatory only when the Catalog Task state is "Closed Complete"

symonflores_23
Tera Guru

An attachment field variable is hidden in the catalog item view and only becomes visible in the Catalog Task. The fulfiller is expected to attach a file to this variable before setting the task to "Closed Complete."

 

While we can use a Catalog UI Policy to make the field mandatory, the problem is that the attachment variable becomes mandatory regardless of the task’s state. This prevents assigning a user to the Catalog Task, as the system requires the attachment before updating the record.

 

How can we configure it so that the attachment variable is only mandatory when the Catalog Task state is set to "Closed Complete"?

 

To clarify, I want to apply a behavior where the mandatory requirement of the catalog item's attachment variable is enforced only when the Catalog Task’s state is "Closed Complete." The attachment variable is hidden from catalog item view.

 

symonflores_23_1-1753436171410.png 

symonflores_23_2-1753436220317.png

 

 

 

1 ACCEPTED SOLUTION

J Siva
Tera Sage

Hi @symonflores_23 
You can achieve this via either client acript or UI policy in the catalog task (sc_task) table.
UI policy sample:

JSiva_0-1753437450704.png
Modify the highlighted variable name as required.

JSiva_1-1753437478299.png


Regards
Siva

View solution in original post

7 REPLIES 7

J Siva
Tera Sage

Hi @symonflores_23 
You can achieve this via either client acript or UI policy in the catalog task (sc_task) table.
UI policy sample:

JSiva_0-1753437450704.png
Modify the highlighted variable name as required.

JSiva_1-1753437478299.png


Regards
Siva

Shruti
Mega Sage
Mega Sage

Hi,

Create a UI Policy on catalog task table

Use g_form.setMandatory('variables.<attachment_variable_name>',true);

 

Shruti_0-1753437533261.pngShruti_1-1753437546595.png

 

Rafael Batistot
Tera Sage

Hi @symonflores_23 

 

Catalog UI Policies apply globally to the task form and cannot evaluate task state transitions, especially conditionally at save/update time.

 

So we need a Business Rule on the sc_task table (Catalog Task) to enforce this logic.

 

Recommended Solution: Business Rule (before update)

 

 

1. Create a Business Rule

  • Table: sc_task
  • When: before update
  • Condition: state changes to Closed Complete
  • Advanced: checked


**** You’ll need to check if the variable set (especially the attachment) is populated

 

(function executeRule(current, previous /*, gForm, gUser */) {

// Only run when transitioning to Closed Complete
if (current.state == 3 && previous.state != 3) { // 3 = Closed Complete

// Retrieve the variable - replace with your actual variable name
var attachmentVar = current.variables.your_attachment_variable_name;

if (!attachmentVar || attachmentVar.getAttachments().length == 0) {
gs.addErrorMessage("Please attach the required file before closing the task.");
current.setAbortAction(true);
}
}
})();