Closing of catalog task restriction

Deepika54
Tera Contributor

Hi experts, I have a use case:

In my RITM Record, there are a couple of Catalog item variables which are mandatory. I want that the catalog task that is linked to the RITM should not be close complete/close incomplete/close skipped until and unless the mandatory RITM variables are filled.

Is there any way we can achieve this. Kindly help

 

Example below are the RITM Variables

Deepika54_0-1781377336604.png

Below is the catalog task where before the task moves to close complete, the RITM variables should be filled and only then the task can be made closed complete/incomplete/skipped

 

Deepika54_1-1781377504926.png

 

1 ACCEPTED SOLUTION

Tanushree Maiti
Tera Patron

Hi @Deepika54 

 

You can use  either  an onSubmit Client Script OR a Business Rule on the sc_task table

 

Option 1 ( this one we have used in our project): Create an OnSubmit  client script on sc_task

  1. Navigate to System Definition > Client Scripts > click New.
  2. Table: sc_task
  3. Type: onSubmit

Sample code: 

 

function onSubmit() {

    var state = g_form.getValue('state');

        // Assuming States: 3=Closed Complete, 4=Closed Incomplete, 7=Closed Skipped)

    if (state == '3' || state == '4' || state == '7') {

        var mandatoryVar = g_form.getValue('variables.VARIABLE_NAME'); // // Replace 'VARIABLE_NAME' with the actual variable name

             if (mandatoryVar == '')

       {

            g_form.addErrorMessage('Please fill out the mandatory RITM variable before closing this task.');

            return false;

        }

    }

}

 

Option 2: Create a BR

  • Navigate to System Definition > Business Rules and click New.
  • Table: sc_task
  • Advanced: Check the box.
  • When: before
  • Insert / Update: Check both.
  • Condition: State changes to Closed Complete OR State changes to Closed Incomplete OR State changes to Closed Skipped.

(function executeRule(current, previous /*null when async*/) {

   var ritm = current.request_item.getRefRecord();

            var manVariable = ritm.variables.VARIABLE_NAME; //Replace 'VARIABLE_NAME' with the actual name of your variable

        if (manVariable.nil()) {

        gs.addErrorMessage('You cannot close this task until the mandatory RITM variable is filled.');

        current.setAbortAction(true);

    }

})(current, previous);

 

 

 

 

View solution in original post

2 REPLIES 2

AndersBGS
Tera Patron

Hi @Deepika54 

 

@you could control the logic with a before business rule to ensure the logic is fulfilled before save to the database.

 

Tanushree Maiti
Tera Patron

Hi @Deepika54 

 

You can use  either  an onSubmit Client Script OR a Business Rule on the sc_task table

 

Option 1 ( this one we have used in our project): Create an OnSubmit  client script on sc_task

  1. Navigate to System Definition > Client Scripts > click New.
  2. Table: sc_task
  3. Type: onSubmit

Sample code: 

 

function onSubmit() {

    var state = g_form.getValue('state');

        // Assuming States: 3=Closed Complete, 4=Closed Incomplete, 7=Closed Skipped)

    if (state == '3' || state == '4' || state == '7') {

        var mandatoryVar = g_form.getValue('variables.VARIABLE_NAME'); // // Replace 'VARIABLE_NAME' with the actual variable name

             if (mandatoryVar == '')

       {

            g_form.addErrorMessage('Please fill out the mandatory RITM variable before closing this task.');

            return false;

        }

    }

}

 

Option 2: Create a BR

  • Navigate to System Definition > Business Rules and click New.
  • Table: sc_task
  • Advanced: Check the box.
  • When: before
  • Insert / Update: Check both.
  • Condition: State changes to Closed Complete OR State changes to Closed Incomplete OR State changes to Closed Skipped.

(function executeRule(current, previous /*null when async*/) {

   var ritm = current.request_item.getRefRecord();

            var manVariable = ritm.variables.VARIABLE_NAME; //Replace 'VARIABLE_NAME' with the actual name of your variable

        if (manVariable.nil()) {

        gs.addErrorMessage('You cannot close this task until the mandatory RITM variable is filled.');

        current.setAbortAction(true);

    }

})(current, previous);