Business Rule condition for Child incident work notes info

Baatyr Patta
Tera Contributor

Hello Community,

 

I have created BR for setting message in work notes field of child incident.

The script is working but, I am struggling with condition. Because the BR is getting executed for all new and existing child incidents.

I need the following condition:
The BR should execute only for a new created child incident. Not for existing child incidents.

Can someone help me?

Should condition be put in the condition field or directly in the script?

BatyrbekAlymku_0-1719052953262.png

 

 

BatyrbekAlymku_2-1719053065351.png

 

4 REPLIES 4

vishakhayadav24
Tera Guru

Hi,

 

When a child incident got created you can sort the child incident by created on and use if not while if you will use while it will run for all the available child incident.

 

 

 

 

Bert_c1
Kilo Patron

Un-check 'Update' and check 'Insert' your BR with then on run on new records being created.  Add:

 

 

grIncident.setWorkflow(false);

 

 

Before the 'grIncident.update();' line to prevent other BRs from running based on you update.

 

Or have the BR run Before and on Insert. and use current.work_notes = 'This incident created from parent Incident' + current.parent.number;. And condition 'parent', 'is not empty'.

 

Naveed_Hussain
Kilo Guru

Hi @Baatyr Patta ,

 

Solution is here:

Step 1: Please uncheck to Update and check on Insert.

Step 2: Goto advance option and add the following code

current.isNewRecord() && gs.isInsert()

OR

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

    // Check if the incident is newly created
    if (current.isNewRecord() && gs.isInsert()) {
        // Your script logic here
        current.work_notes = "Your message for new incidents";
        // Save the record if needed
        current.update();
    }

})(current, previous);

 

If you think my answer is helpful for you or solves your problem then click on helpful or mark it as a solution

 

Regards

Naveed_Hussain

current.update() should not be used in a Before and Insert BR.

 

 

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

	// Add your code here
	current.work_notes = 'This incident is created with parent: ' + current.parent.number;

})(current, previous);

 

is all that is needed if the Condition field on the When to run tab has 'Parent', 'is not empty'.

 

business-rules

 

However, seems Batyrbek Alymku post is missing some details on how a child incident is created.