Business Rule for updating child task when parent record gets updated

Dipali Pawar2
Tera Contributor

Hi, we are working on SLA related to task , when the parent case state is awaiting info we need to set the SLA for related case task to 'Paused' state. 

since only the case record is getting updated with the state the SLA for case task remains unchanged. 

with the update to any field in the case task record we are able to see the correct state of SLA .

so to update the case task we have written a business rule to update the work notes, below is the script 

DipaliPawar2_0-1674131240351.png

DipaliPawar2_0-1674131450640.jpeg

we are not able to see any update in case task record , please let us know what are we missing here.

Thanks in advance 

4 ACCEPTED SOLUTIONS

Omkar Ranjane
Tera Guru

Hi @Dipali Pawar2 

 

Create Before Update Business Rule with condition state changes to awaiting info or state changes to open & try below code snippet.

 

(function executeRule(current, previous /*null when async*/ ) {
    var caseTask = new GlideRecord("sn_customerservice_task");
    caseTask.addQuery("parent", current.sys_id);
    caseTask.query();
    while (caseTask.next()) {
        caseTask.work_notes = "Testing";
        caseTask.update();
    }
})(current, previous);

 

 

If your question is solved, please close the topic by marking my answer "Accept as Solution". This will help others searching for a similar question and will remove the topic from the unsolved list.

 

View solution in original post

kalyan13
Tera Guru

Hi @Dipali Pawar2 ,

Please try @Omkar Ranjane  solution, if you still unable to get the solution let me know 

Regards,

Kalyan 

View solution in original post

Hello @Omkar Ranjane .

Thanks for the code, worked like a charm!

I have a similar requirement and the case task is getting updated on change of state. One additional implementation which we are looking is to get the current state of the parent case.

I tried using 

current.top_task.getDisplayValue('state');

current.parent.getDisplayValue('state');

 

Both are bringing undefined value, Kindly help on this

Below is the script and screen shot:

 

Gokul24_0-1674303442741.png

 

 

(function executeRule(current, previous /*null when async*/ ) {
var caseTask = new GlideRecord("sn_customerservice_task"); //Gliding Case Task
caseTask.addQuery("parent", current.sys_id); //Checking if Case task has parent
caseTask.query();
while (caseTask.next()) { //if case task exist , updating work notes
var parent_case_state =current.top_task.getDisplayValue('state');
caseTask.work_notes = "Case State updated to" + parent_case_state;
caseTask.update();
}
})(current, previous);

View solution in original post

Hello @Omkar Ranjane @kalyan13 

I have figured out the error. 
Below is the code and snapshot 

 

 

 

(function executeRule(current, previous /*null when async*/ ) {
var caseTask = new GlideRecord("sn_customerservice_task"); //Gliding Case Task
caseTask.addQuery("parent", current.sys_id); //Checking if Case task has parent
caseTask.query();
while (caseTask.next()) { //if case task exist , updating work notes
var parent_case_state = current.getDisplayValue('state');
caseTask.work_notes = "Case state has been updated to" + " " + parent_case_state;
caseTask.update();
}

})(current, previous);

 

 



Gokul24_0-1674310024923.png


Thanks for the inputs

View solution in original post

11 REPLIES 11

Sebastian R_
Kilo Sage

In your script you are setting the work_notes of the current record instead of myObj (child cases). Also you have to update the records using myObj.update().

Also in your query you are missing the relationship to the parent so you would update all cases in state 10,18.

Hi Sebastian , thank you for your reply . 
Got your point , could you please elaborate how to create relationship between parent and child. 

we tried parent.case unfortunately missing out the logic on reaching of the parent of the case task . 

Sonu Parab
Mega Sage
Mega Sage

Hi @Dipali Pawar2 
Please try below BR script

 

 

var myObj = new GlideRecord('sn_customerservice_task);
myObj.addQuery('sys_id',  parent_case_record_field);  //  here parent_case_record_field which store parent case number on  sn_customerservice_task table.
myObj.query();
if (myObj.next()){
 myObj.work_note = "Testing";
myObj.update();
}

 

let us know if any issue occur.
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

 

Hi @Sonu Parab 

Thanks for the response, we tried using your script, but unfortunately it doesn't seem to work, when we update any fields in the case, the worknotes in case task are not getting updated.. 

DipaliPawar2_0-1674195791316.pngDipaliPawar2_1-1674195801669.png

 

We tried a sample filter condition of when Case Category changes, the worknotes of the case task related to that case  should be updated.

 

Kindly let us know what are we missing here