- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2020 10:20 PM
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);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2020 10:06 PM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2020 10:31 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2020 03:10 PM
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()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2020 09:33 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2020 10:06 PM
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);
}