Need help in Before Insert Business Rule

Community Alums
Not applicable

HI Team,

 

I am using Before Insert BR to auto-populate/save the 3 fields on the child task which I am getting it by gliding the parent i.e customer_project  as below:

Other than manually creating the task, there is also a way task is getting created from FlowDesigner , in such case how can we update the record, as current.update cannot be used in BR as best practise.

 

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

    // Add your code here
    
    
var gr=new GlideRecord('customer_project');
    gr.addQuery('number',current.top_task.number);
    gr.query();
    if(gr.next()){
        gs.info('Hello :'+ gr.u_order);
        current.u_service_delivery_contact=gr.u_service_delivery_contact;
        current.u_location_child_account=gr.account;
        current.u_customer_order=gr.u_order;
        
    }
})(current, previous);

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hello,

In a before business rule the "current" object doesn't need current.update() as it's already going to be updated naturally without it when setting values to current.field_name, etc.

Have you tried?

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

3 REPLIES 3

Allen Andreas
Administrator
Administrator

Hello,

In a before business rule the "current" object doesn't need current.update() as it's already going to be updated naturally without it when setting values to current.field_name, etc.

Have you tried?

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Jacob Nan
Tera Guru

Is the child task being created when the parent is created? In that case you wouldn't be able to update the fields because it had yet to be created in a "before insert" situation.

Make sure this business rule is referring to the child incident/task. That way the parent is created and before the child is created, the rule kicks off.

Aman Kumar S
Kilo Patron

You don't need to GlideRecord the Customer project table, you can directly dot walk and get the value:

current.u_service_delivery_contact=current.top_task.u_service_delivery_contact;
current.u_location_child_account=current.top_task.account;
current.u_customer_order=current.top_task.u_order;

 

Alternatively, it can also be to directly set as default value at dictionary level, you can go to dictionary and set default value as following:

For u_customer_order field:

javascript: current.top_task.u_order;

Similarly, you can do for other fields.

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

 

 

 

Best Regards
Aman Kumar