Rejection Comments in email not appearing

Troy S_
Kilo Expert

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:

        find_real_file.png

The field I am pulling in from is:

        find_real_file.png

Thank you in advance for your help on this issue.

Troy

1 ACCEPTED SOLUTION

reginabautista
Kilo Sage

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>


View solution in original post

13 REPLIES 13

reginabautista
Kilo Sage

I think you need to get the journal entries..



var notes = appr.work_notes.getJournalEntry(-1);


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');




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


reginabautista
Kilo Sage

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


reginabautista
Kilo Sage

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