- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2020 01:14 PM
Hello,
I have written a business rule that copies comments from an approval record to the activity stream of the parent record. This took some trial, error, and community support as I am not typically a developer, I just play one since our institution has been forced to down-size over the past year.
My issue now is that I want to augment this business rule so that it does nothing if comments field is blank or the activity stream on the approval record does not have a comments entry.
Currently it adds "Approval Comments:" to the parent record for all approvals rather than approvals that have comments. I feel like I'm missing an additional else statement but I have yet to figure out anything that will work.
(function executeRule(current, previous /*null when async*/ ) {
var comments;
if (current.comments != '') {
comments = current.comments;
} else {
comments = current.comments.getJournalEntry(1);
}
var gr = current.sysapproval.getRefRecord();
gr.comments = "Approval Comments: \n\n" + comments;
gr.update();
})(current, previous);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2020 01:19 PM
Hi Cody,
Below should help.
(function executeRule(current, previous /*null when async*/ ) {
var comments;
if (current.comments != '') {
comments = current.comments;
} else {
comments = current.comments.getJournalEntry(1);
}
var gr = current.sysapproval.getRefRecord();
if(comments!='') //if there is something only then if will work
{
gr.comments = "Approval Comments: \n\n" + comments;
}
else{//do nothing}
gr.update();
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2020 01:19 PM
Hi Cody,
Below should help.
(function executeRule(current, previous /*null when async*/ ) {
var comments;
if (current.comments != '') {
comments = current.comments;
} else {
comments = current.comments.getJournalEntry(1);
}
var gr = current.sysapproval.getRefRecord();
if(comments!='') //if there is something only then if will work
{
gr.comments = "Approval Comments: \n\n" + comments;
}
else{//do nothing}
gr.update();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2020 01:45 PM
Thank you Jaspal for your quick response. Your assistance has helped me find a solution.
I ran into some issues with the script you provided but I was able to find success by making a few slight adjustments. Initially it wasn't copying anything over until I added gr.update(); to the if statement validating that the comments variable is not empty.
(function executeRule(current, previous /*null when async*/ ) {
var comments;
if (current.comments != '') {
comments = current.comments;
} else {
comments = current.comments.getJournalEntry(1);
}
var gr = current.sysapproval.getRefRecord();
if (comments !='')
{
gr.comments = "Approval Comments: \n\n" + comments;
gr.update();
}
else{
gr.update();
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2020 01:48 PM
Great to know it worked. You can close the thread by marking thread as correct so that it does not appear in unanswered list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2021 03:36 AM
I am searching for the similar requirement and thankfully I found this thread.
There is a requirement from client to update the RITM comments with the approval comments.
I used the code in this thread and it is working absolutely fine. But there is a small correction needed on this in my scenario.
Well, In a particular RITM If there are 4 approvals having (same)comments in all those approvals then the RITM comments are getting updated 4 times.
Can we make any modifications in this code so that only once the RITM comments will get updated?