- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2017 07:11 AM
I have the following <mail_script>in my Workflow Notification:
<mail_script>
//get the related approvals for this change
//check for any reject and display comments
//create a new glide record query for approval records
var appr = new GlideRecord('sysapproval_approver');
//get approvals for this change
appr.addQuery('sysapproval',current.sys_id);
//get rejected approvals
appr.addQuery('state','rejected');
//execute the query
appr.query();
//process each result if there are any
if (appr.next()) {
//print the approval info to the email message
template.print('Approver: ' + appr.approver.getDisplayValue() + '\n');
template.print('State: ' + appr.state) + '\n';
template.print('Comments: ' + appr.comments + '\n');
template.print('\n');
}
</mail_script
It is returning the following:
The field I am pulling in from is:
Thank you in advance for your help on this issue.
Troy
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2017 05:37 AM
Hi Troy try changing the gs.log to template.print as below
<mail_script>
//get the related approvals for this change
//check for any reject and display comments
var notes;
//create a new glide record query for approval records
var appr = new GlideRecord('sysapproval_approver');
//get approvals for this change
appr.addQuery('sysapproval',current.sys_id);
//get rejected approvals
appr.addQuery('state','rejected');
//execute the query
appr.query();
//process each result if there are any
while (appr.next()) {
var je = new GlideRecord('sys_journal_field');
je.addQuery('element_id', appr.sys_id);
je.addQuery('elements', 'comments');
je.addQuery('name', 'sysapproval_approver');
je.query();
if(je.next()){
notes = je.value;
}
//print the approval info to the email message
template.print('Approver: ' + appr.approver.getDisplayValue() + '\n');
template.print('State: ' + appr.state) + '\n';
template.print('Comments: ' + notes + '\n');
template.print('\n');
}
</mail_script>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2017 07:46 AM
I think you need to get the journal entries..
var notes = appr.work_notes.getJournalEntry(-1);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2017 07:55 AM
This thread might help too:
Getting the first record of a Journal Entry
if you only need to get the last entry then use this:
var notes = appr.work_notes.getJournalEntry(1);
template.print('Comments: ' + notes + '\n');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2017 10:09 AM
I tried that and several variations on the appr.work_notes such as appr.comments or appr.activity and they all come back as undefined. Thank you again for your help.
This is what my code now says:
<mail_script>
//get the related approvals for this change
//check for any reject and display comments
//create a new glide record query for approval records
var appr = new GlideRecord('sysapproval_approver');
//get approvals for this change
appr.addQuery('sysapproval',current.sys_id);
//get rejected approvals
appr.addQuery('state','rejected');
//execute the query
appr.query();
var notes = appr.work_notes.getJournalEntry(1);
//process each result if there are any
while (appr.next()) {
//print the approval info to the email message
template.print('Approver: ' + appr.approver.getDisplayValue() + '\n');
template.print('State: ' + appr.state) + '\n';
template.print('\n');
//template.print('Comments: ' + appr.comments + '\n');
template.print('Comments: ' + notes + '\n');
template.print('\n');
}
</mail_script>
Thank You
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2017 05:49 PM
Hi Troy,
The note variable should be added inside the while loop. I'm not sure why getJournalEntry is not working but I've modified the code..here's what worked for me when I ran this in background script. Just change gs.log to template.print
//get the related approvals for this change
//check for any reject and display comments
var notes;
//create a new glide record query for approval records
var appr = new GlideRecord('sysapproval_approver');
//get approvals for this change
appr.addQuery('sysapproval',current.sys_id);
//get rejected approvals
appr.addQuery('state','rejected');
//execute the query
appr.query();
//process each result if there are any
while (appr.next()) {
var je = new GlideRecord('sys_journal_field');
je.addQuery('element_id', appr.sys_id);
je.addQuery('elements', 'comments');
je.addQuery('name', 'sysapproval_approver');
je.query();
if(je.next()){
notes = je.value;
}
//print the approval info to the email message
gs.log('Approver: ' + appr.approver.getDisplayValue() + '\n');
gs.log('State: ' + appr.state) + '\n';
gs.log('Comments: ' + notes + '\n');
gs.log('\n');
}
Here's the result:
*** Script: Approver: Luke Wilson
*** Script: State: rejected
*** Script: Comments: test reject
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2017 05:18 AM
Hi Troy may I ask if this issue is resolved? Could you mark my answer correct if it helped so it gets removed from unanswered list? Thanks