Attempting to copy comments from Approval Record to Contract Activity stream

Aaron Duncan
Mega Sage

I'm using a Business Rule to take the comments from an Approval record and copy them to the corresponding Contract record. 

 

I have it set to run when the Source Table is ast_contract, the approval state is requested, and the Comments changes.

It runs after an update. Here is my code. However on the resulting contract record, I get the following (see screenshot below).

 

 

 

(function executeRule(current, previous /*null when async*/ ) {
    var comments;
    current.comments = "Test Comment";
    if (current.comments != '') {
        comments = current.comments;
    } else {
        comments = current.comments.getJournalEntry(1);
    }
    var gr = current.document_id.getRefRecord();
	if (comments !='')
	{
		gr.comments = "Approval Comments: \n\n" + comments;
	gr.update();
	}
	else{
    gr.update();
	}
gr.update();
})(current, previous);

 

 

 I have checked over and over, but not sure why it's only passing the dates from the contract into the comments field on the contract. I just want it to show the notes.

AaronDuncan_1-1682113788970.png

 

 

1 ACCEPTED SOLUTION

Mallidi Suma
Tera Guru

Hi @Aaron Duncan ,

 

Create an after-update a Business rule on the Approval table.  Please find the below screenshots of my code and Business Rule(Change the state condition as per your requirement)

MallidiSuma_0-1682192470588.png

 

Code:-

 

var gr = new GlideRecord('ast_contract');
gr.addQuery('sys_id',current.document_id);
gr.query();
if(gr.next())
{
gr.u_comments = current.comments.getJournalEntry(1);
gr.update();
}

 

Please mark my solution as helpful, if it helps!!

 

 

Please try the below code

var gr = new GlideRecord('ast_contract');
gr.addQuery('sys_id',current.document_id);
gr.query();
if(gr.next())
{
gs.addInfoMessage("Entered into the if");
gr.u_comments = current.comments.getJournalEntry(1);
gr.update();

View solution in original post

3 REPLIES 3

Mallidi Suma
Tera Guru

Hi @Aaron Duncan ,

 

Create an after-update a Business rule on the Approval table.  Please find the below screenshots of my code and Business Rule(Change the state condition as per your requirement)

MallidiSuma_0-1682192470588.png

 

Code:-

 

var gr = new GlideRecord('ast_contract');
gr.addQuery('sys_id',current.document_id);
gr.query();
if(gr.next())
{
gr.u_comments = current.comments.getJournalEntry(1);
gr.update();
}

 

Please mark my solution as helpful, if it helps!!

 

 

Please try the below code

var gr = new GlideRecord('ast_contract');
gr.addQuery('sys_id',current.document_id);
gr.query();
if(gr.next())
{
gs.addInfoMessage("Entered into the if");
gr.u_comments = current.comments.getJournalEntry(1);
gr.update();

On the query, I just made a minor adjustment and it worked great!

grContract.addQuery("sys_id", current.getValue('document_id'));

Jakob Anker
ServiceNow Employee
ServiceNow Employee

Hi Aaron. 

Please have a look at my post. It might be helpful.

https://www.servicenow.com/community/in-other-news/sn-tip-13-synch-comments-and-work-notes/ba-p/2430...