The CreatorCon Call for Content is officially open! Get started here.

setWorkflow(false) use in business rule

VullankiL
Tera Contributor

Hi 

I have one scenario, where I am using setWorkflow(false).

 

VullankiL_0-1736767804068.png

 

But in my case, there is no workflow associated with the table. But I want to stop executing remaining business rules associated with it. (Because there is another business rule that can abort this cancel action) Can I use it or not? Is there is any other option to stop execution of other business rules in this case?

Thank you

17 REPLIES 17

This might be a scope issue. 

Can both ACLs be in same scope?

-Anurag

Hi @VullankiL 

 

Use a "Flag" Field and a Before Business Rule:

This is often the recommended approach when dealing with cross-scope issues and wanting to prevent other business rules from executing.

Add a Flag Field: Add a custom field (e.g., u_skip_br_processing, type: true/false) to the asmt_assessment_instance table in the Global scope.
Set the Flag: In your current business rule (in the "EITG" scope), instead of calling setWorkflow(false) directly, set this new flag field to true on the asmt_assessment_instance record.
Create a Before Business Rule in Global: Create a new "before" business rule on the asmt_assessment_instance table (in the Global scope) with a high order value (e.g., 50). This rule should have the following logic:Condition: current.u_skip_br_processing == true

 

// Business Rule: After - Update on [Your Table] 
// Scope: x_weoi2_eitg_confi (or EITG)
// Order: 1000 (or higher)

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

    var gr = new GlideRecord('asmt_assessment_instance'); 
    gr.addQuery('related_id_1', current.related_id_1);
    gr.addEncodedQuery('state!=complete^ORstate=NULL'); 
    gr.query();
    while (gr.next()) {
        gr.setValue('state', 'canceled');

        // Set the flag field to prevent other business rules from running
        gr.u_skip_further_br = true; 

        //Update the record
        gr.update();
    }

})(current, previous);

If you like this opinion and your problem is resolved after reviewing and applying it. Please kindly mark this your best answer‌🌠‌ OR  mark it  Helpful ‌‌ if you think that you get some insight from this content relevant to your problem and help me to contribute more to this community

MackI | ServiceNow Technical Consultant | DXC Technology Australia | ServiceNow Practice | LinkedIn Top IT Operation Voice 2023 | Sydney,Australia

Runjay Patel
Giga Sage

Hi @VullankiL ,

 

setWorkflow(false) is used to prevent workflow execution on a record update. However, if there are other business rules (such as before business rules or after business rules) that you want to skip, setWorkflow(false) won't stop those from executing by itself.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

Hi @Runjay Patel ,

Even after using setWorkflow(false) in my business rule, it is executing another business rule (to abort cancel action). I don't want to execute it.
I am writing the current business rule for Assessment instances table (Global scope). But the updating record is in another scope (scoped). And setWorkflow(false) showing some security constraints. How can I solve it? please let me know..

Thank you,

Hi @VullankiL ,

 

If you do setWorkflow(false) in global scope it will only stop the business rule execution in that scope and not  in other two scoped application. Similarly if you do setWorkflow in one scope app it will only stop BR execution for BR related to that scope and not for global scope and other scope app.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------