The CreatorCon Call for Content is officially open! Get started here.

Getting approval comments into work notes

Community Alums
Not applicable

Hi all

I'm trying to copy approval comments to the work notes on a table which is not of task. I'm doing this in the workflow editor. The workflow waits for a condition, then fires off the approval. If approved I need the approval notes to be added to the work notes of the table I'm on, and some other stuff done. 

Everything is working as it should bar the approval notes. This is what I currently have in the script. Any suggestions?

var gr = new GlideRecord("sysapproval_approver");
gr.addQuery('sysapproval', current.sysapproval);
gr.query();
if(gr.next()) {
current.work_notes = gr.getJournalEntry(1);

}

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Thanks Ankur

I'm so sorry, I should have updated this thread a couple of hours ago. 

I found a solution that worked. I needed to use document Id as that is for non-task approvals:

var gr = new GlideRecord("sysapproval_approver");
gr.addQuery('document_id', current.sys_id);
gr.addQuery('state','approved');
gr.orderByDesc('sys_updated_on');
gr.query();
if(gr.next()) {
current.work_notes = gr.comments.getJournalEntry(1);
}

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I assume your workflow is on your table and you want to update it's work_notes with the approval comments

so update as below if the workflow is on your table

var gr = new GlideRecord("sysapproval_approver");
gr.addQuery('sysapproval', current.sys_id);

gr.addQuery('state','approved');
gr.query();
if(gr.next()) {

current.work_notes = gr.comments.getJournalEntry(1);

current.update();

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Community Alums
Not applicable

Hi Ankur

Thanks for the suggestion. Yes, the workflow is on the alm_asset table and I want to update the asset records work notes with the approval comments. 

 

The workflow is firing but your suggested script still doesn't work; the approval comments do not get pasted into the work notes. 

I do also get a warning in the workflow when validating as its using current.update()

find_real_file.png

Hi James,

can you try this

var gr = new GlideRecord("sysapproval_approver");
gr.addQuery('sysapproval', current.sys_id);

gr.addQuery('state','approved');
gr.query();
if(gr.next()) {

var rec = new GlideRecord('alm_asset');

rec.get(current.sys_id);

rec.work_notes = gr.comments.getJournalEntry(1);

rec.update();

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Community Alums
Not applicable

Thanks Ankur

I'm so sorry, I should have updated this thread a couple of hours ago. 

I found a solution that worked. I needed to use document Id as that is for non-task approvals:

var gr = new GlideRecord("sysapproval_approver");
gr.addQuery('document_id', current.sys_id);
gr.addQuery('state','approved');
gr.orderByDesc('sys_updated_on');
gr.query();
if(gr.next()) {
current.work_notes = gr.comments.getJournalEntry(1);
}