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

Pass comments from UI page to sysapproval_approver record

Matthew Glenn
Kilo Sage

hey all,

 

I have a UI page that I recenty built to accommodate mobile approvals for a custom table and I need to pass text captured from a JavaScript prompt to the comment/journal field on the sysapproval_approver record.

 

Below is the relevant code I have right now:

 

HTML/Button

 

<input type="button" name="comment" value="Send Back" onclick="sendback()" style="background-color:yellow"></input>

 

Client Script

function sendback() {
   var comments = prompt("Please specify what needs to change on this specific Invoice", "");

   //if comments are entered in the box
   if (comments != ""){
   alert('This Invoice has been sent back so that these adjustments can be made.')
   var approval = new GlideRecord('sysapproval_approver');     
   approval.addQuery('sys_id','=','$[jvar_approval_sysid]');
   approval.addQuery('status','=','requested');
   approval.query();
   while(approval.next()) { 
           approval.state = 'adjustment'; //set approval to 'adjustment'
   //approval.comments.setJournalEntry();         //set approval comments to note section. will be logged and emailed out to submitter
   //approval.setJournalEntry(comments);
   //approval.comments = gel('comment').value;
           approval.update();                                                                             //update approval 
                   var record = new GlideRecord('u_invoices');
                   record.addQuery('sys_id','=',approval.document_id);   //find invoice record with same sysid as approval.document_id
                   record.query();
                   while(record.next()){
                           record.update();                                                                 //update record
                   }
           }
   }
   //otherwise
   else 
   {
   alert("We need to provide a reason when we send this Invoice back to the original submitter. \n\nPlease click on the 'Send Back' button again and specify what needs to be changed.");
   }
         location.reload();
}

 

 

 

Everything works in the above code, with the exception of me not being able to grab the text entered in the 'prompt' and send that to the comment/journal field on the related approval.

 

As you can see in lines 13-15 I have a few meger attempts at passing the value back, but I just can't seem to write back to the journal.

 

Can anyone help?

1 ACCEPTED SOLUTION

Matthew Glenn
Kilo Sage

I was able to create a work-around for this issue by creating a new field on the sysapprova_approver table and storing the comments in there. Not the way I'd like to do it but it technically serves the same purpose. I'm now able to store the comments and grab them for email notification as necessary.



Thank you to all that have assisted. I believe I'm 1-2 tweaks away from getting it but unfortunately need to go with the work-around for the time being.



I'll continue to work on this and update when I have some free time down the road.


View solution in original post

13 REPLIES 13

Jim Coyne
Kilo Patron

Try just:


approval.comments = comments;



The setJournalEntry method is a server-side only GlideRecord method.


Unfortunately that's not doing much either.



Ultimately I'm trying to get the comments gathered from this prompt to show up on the approval similar to the entry below, which was done via an approval UI Macro using the comment field.


activity.PNG



On a related note, part of this process takes the comments/journal entries that are left on the approval and emails them back to the 'owner' of the record. That is done via a <mail_script> on a workflow notification. That email (sample image below) is seeing that a journal entry is being created, but just isn't logging the comments


approvals.png



The comments you see were created via the UI Macro. The entries you see without a comment were created via the UI Page.



Any other ideas?


kungfuu72
Giga Expert

I see that you are doing this all in the Client Script.



The "comments" variable can be passed to the Processing Script instead of actually allowing the Client Script to do the updating.



Another issue that may be problematic is on line 8:



approval.addQuery('sys_id','=','$[jvar_approval_sysid]');



I'm not completely sure if you can reference a jelly variable in the client script like this.



If you just want the unique sys_id of the approval record, and you're currently on the approval record you can use:



var sysid = gel('sys_uniqueValue').value;



You might want to add some console.logging in your while loop to see if your GlideRecord query is actually getting the record(s) you want.


I think u have to use journal entry...since dose r journal fields



like dis,



var notes = current.work_notes.getJournalEntry(-1); //gets all journal entries as a string where each entry is delimited by '\n\n'


var na = notes.split("\n\n");     //stores each entry into an array of strings



for (var i = 0; i < na.length; i++)    


  gs.print(na[i]);


Regards
Harish