Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to Trigger Business Rule from Related Record Changes?

thullurishalini
Kilo Guru

Hi everyone,

I need to trigger a business rule in a parent record (e.g., Incident) when a field in a related child record (e.g., Work Note) is updated.

4 ACCEPTED SOLUTIONS

Aditya02
Tera Guru

Hi @thullurishalini ,

 

I accomplished this by creating a business rule on the Work Note (Journal) table (sys_journal_field) that updates a field in the parent Incident when a work note is modified. This in turn triggers a business rule on the parent Incident.

 

You can follow the below steps and Code for business rule to achieve this:

  • Create a Business Rule on the Work Note (Journal) table (sys_journal_field).
  • In the Business Rule:
          a. When: After
          b. Condition: You can specify your own condition, such as when a specific field is updated.
          c. Script:

(function executeRule(current, previous /*null when async*/) {
       if (current.element_id == 'incident') {                                 // Check if the work note is related to an incident
             var incidentGR = new GlideRecord('incident');           // Get the parent incident record
             if (incidentGR.get(current.element)) {
                         // Write the script what you want to perform
              }
       }
})(current, previous);

 

 

 

===================================***************=========================================

"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"

 

Thanks & Regards,

Aditya

=====================================***********==========================================

 

 

View solution in original post

brahmandlapally
Giga Guru

Hi @thullurishalini.

Create a After BR on table (sys_journal_field) so whenever the worknote updated the BR triggers

Thank you

View solution in original post

Anantha27
Mega Guru

Hi @thullurishalini 

You can use the script in the BR at the advance tab as follows

if (current.your_field_name.changes()) {
   var parentRecord = new GlideRecord('incident');
   if (parentRecord.get(current.parent)) {         

parentRecord.state = '3'; 
       parentRecord.update();
   }
}

This may help you to trigger the BR

Thank you

View solution in original post

Sai Krishna6147
Mega Guru

Hi @thullurishalini 

Please refer to this link. It may helps to you
Refer: https://www.servicenow.com/community/developer-forum/need-business-rule-to-update-parent-state/m-p/1... 

Please mark this response as correct or helpful if it assisted you with your question.

Thank you

View solution in original post

10 REPLIES 10

Aditya02
Tera Guru

Hi @thullurishalini ,

 

I accomplished this by creating a business rule on the Work Note (Journal) table (sys_journal_field) that updates a field in the parent Incident when a work note is modified. This in turn triggers a business rule on the parent Incident.

 

You can follow the below steps and Code for business rule to achieve this:

  • Create a Business Rule on the Work Note (Journal) table (sys_journal_field).
  • In the Business Rule:
          a. When: After
          b. Condition: You can specify your own condition, such as when a specific field is updated.
          c. Script:

(function executeRule(current, previous /*null when async*/) {
       if (current.element_id == 'incident') {                                 // Check if the work note is related to an incident
             var incidentGR = new GlideRecord('incident');           // Get the parent incident record
             if (incidentGR.get(current.element)) {
                         // Write the script what you want to perform
              }
       }
})(current, previous);

 

 

 

===================================***************=========================================

"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"

 

Thanks & Regards,

Aditya

=====================================***********==========================================

 

 

brahmandlapally
Giga Guru

Hi @thullurishalini.

Create a After BR on table (sys_journal_field) so whenever the worknote updated the BR triggers

Thank you

Anantha27
Mega Guru

Hi @thullurishalini 

You can use the script in the BR at the advance tab as follows

if (current.your_field_name.changes()) {
   var parentRecord = new GlideRecord('incident');
   if (parentRecord.get(current.parent)) {         

parentRecord.state = '3'; 
       parentRecord.update();
   }
}

This may help you to trigger the BR

Thank you

Sai Krishna6147
Mega Guru

Hi @thullurishalini 

Please refer to this link. It may helps to you
Refer: https://www.servicenow.com/community/developer-forum/need-business-rule-to-update-parent-state/m-p/1... 

Please mark this response as correct or helpful if it assisted you with your question.

Thank you

Ramesh_143
Giga Guru

Hi @thullurishalini , 

 

You can follow the below steps and Code for business rule to achieve this:

  • Create a Business Rule on the Work Note (Journal) table (sys_journal_field).
  • In the Business Rule:
          a. When: After
          b. Condition: You can specify your own condition, such as when a specific field is updated.
          c. Script:  
    var workNoteGR = new GlideRecord('work_note');
    workNoteGR.addQuery('incident', current.sys_id);
    workNoteGR.query();
    while (workNoteGR.next()) {
    if (workNoteGR.field_name.changes()) {
    current.field_to_update = 'new_value';
    current.update();
    }
    }

    Thanks & Regards,

    Ramesh

    Please mark this response as correct or helpful if it assisted you with your question.