Copy the work notes of child to its direct Parent

Elena Spıru
Mega Guru

Hello,

 

I have added a related list on problem table called Child problems (which shows all children the particular problem has).

Now I need to add a logic that copies the work notes from child to its direct parent and I have the following scenario:

Problem A is the parent of Problem B

Problem B is the parent of Problem C

 

scenario 1: When the user writes a comment in work notes in Problem C, I want the specific work note to be copied only to Problem B's work notes.

scenario 2: When the user writes a comment in work notes in Problem B, I want it to be copied to Problem A

 

I created a business rule that copies the work notes correctly BUT the issue is that for scenario 1, the work notes get copied to Problem's B work notes, then it gets copied to Problem A's work notes - which is not desired.

 

Is there a solution to this?

 

Thank you,

Elena

1 ACCEPTED SOLUTION

@Elena Spıru 
yeah you cannot add that in condition here but you can add it in the script in IF condition.

Sample script for your reference

var text = "ServiceNow makes work better"; //this is whole comment
var substring = "work";  //substring to check copied from 

if (text.includes(substring)) {
  console.log("Substring found!");  //dont copy the worknotes in this case
} else {
  console.log("Substring not found.");  //copy the worknotes in this loop.
}

 

Accept the solution and mark as helpful if it does, to benefit future readers.
Regards,
Sumanth

View solution in original post

18 REPLIES 18

@SumanthDosapati it is brilliant!
This is the final code:

ElenaSpru_0-1747384602315.png

 

Thanks! Will do a couple of tests to make sure it works as expected in all scenarios, but it looks fine. 😀

@Elena Spıru 

Glad that it helped. Accept the solution and mark as helpful so that it benefits future readers.

 

Regards,

Sumanth

Sure, let me test it for all the scenarios: such as from problem task, to child problem, to child problem, to parent problem and so on
If this works, I will mark it as helpful...if not, I will mention you...haha!

Feel free to mention anytime 😊