"Wait for condition" + "Business Rule" do not execute as expected

ronro2
Tera Contributor

Hello guys! 

I have a problem regarding a specific Catalog Item's sc_task (SCTASK). Update: The workflow is based on sc_req_item table. This specific task has the following "Wait for condition" script in the workflow: 

 

 

if (!gs.nil(current.project_resource)) {
    // continue workflow
    answer = true;
} else {
    // wait until field project_resource is not empty
    answer = false;
}

 

 


The Business Rule, based on sc_task table, is configured as follows: 
- When: before 
- Selected: Update + Insert
- Here is the following Business Rule script: 

 

 

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

       // Kontrollera om det är en specifik catalog item
    var catalogItemSysId = '0f0278598c2a1e10ebb6ef259418f246'; // catalog item Teknisk resursförfrågan.
    if (current.cat_item == catalogItemSysId) {
        
        // Kontrollera om state är satt till 3 (Avslutad)
        if (current.state == 3) {
            
            // Kontrollera om project_resource är ifyllt
            if (gs.nil(current.project_resource)) {
                gs.addErrorMessage('Du kan inte avsluta denna uppgift förrän "project_resource" är ifyllt.');
                current.setAbortAction(true); // Stoppa uppdateringen
            } else {
                current.setAbortAction(false); // Tillåt uppdateringen
            }
        }
    }

})(current, previous);

 

 

 
The problem: When I select a value for the project_resource field and I change the state of the SCTASK to 3 (Closed Complete) and save, I get the error message (that is only supposed to come when trying to close the SCTASK without a value in the project_resource field).

 

Update: the project_resource field is a custom field made for a specific catalog item. 

Any ideas why? It is so frustrating and I just don't get why it is not working. 

Thanks in advance!

2 ACCEPTED SOLUTIONS

Brad Bowman
Kilo Patron
Kilo Patron

To clarify, this Business Rule is running on the sc_task table?  'project_resource' is not the name of an out of box field on the sc_task table.  If you have added this field to the table, check the name.  If this is a Catalog Item variable, then use:

            if (gs.nil(current.variables.project_resource)) {

The same syntax would be used in the workflow script.

View solution in original post

Did you update the Wait for condition script?

if (!gs.nil(current.variables.project_resource)) {
    // continue workflow
    answer = true;
} else {
    // wait until field project_resource is not empty
    answer = false;
}

View solution in original post

10 REPLIES 10

Brad Bowman
Kilo Patron
Kilo Patron

To clarify, this Business Rule is running on the sc_task table?  'project_resource' is not the name of an out of box field on the sc_task table.  If you have added this field to the table, check the name.  If this is a Catalog Item variable, then use:

            if (gs.nil(current.variables.project_resource)) {

The same syntax would be used in the workflow script.

Hey Brad, I'm truly sorry for missing out on crucial details. Yes, the BR is based on the sc_task table. And "project_resource" is a field specific to a certain catalog item with the sys ID visible in the BR script. So it's not an out of box field. 

By the way, your solution regarding the Business Rule seems to work! Thank you so so much!

However, the flow is supposed to continue to the next activity (a Set Values activity) based on sc_req_item table. This activity contains the following condition: state=3^EQ (supposed to put the parent sc_req_item in Closed Complete). It doesn't do that, the flow doesn't continue beyond the Wait for condition described earlier. 

I guess the Wait for condition needs a current.variables as well, right? 

Did you update the Wait for condition script?

if (!gs.nil(current.variables.project_resource)) {
    // continue workflow
    answer = true;
} else {
    // wait until field project_resource is not empty
    answer = false;
}