- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2014 12:50 PM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2014 12:10 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2014 09:18 PM
The reference to the Jelly variable works quite well, actually. I'm having no issues with there.
I understand what you mean by passing the comments to the processing script. I'll give that a shot next. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2014 10:35 AM
Yep. So I am absolutely stuck here.
Recap: I'm pulling information to a stand alone UI Page from a custom table. I'm then plugging some of that info into the Client Script section (one of a few functions in the Client Script section - note that the code below is updated from the original post):
function backinv(aprSysID) {
//if comments are entered in the box
var approvercomment = gel('adjustmentreasons');
if (approvercomment != ""){
alert('Thank you. This Invoice has been sent back so that these adjustments can be made.');
var approval = new GlideRecord('sysapproval_approver');
approval.addQuery('sys_id','=',aprSysID);
approval.addQuery('status','=','requested');
approval.query();
while(approval.next()) {
//alert('these are my comments: ' + approvercomment);
approval.state = 'adjustment'; //set approval to 'adjustment'
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("You need to provide a reason as to why this request is being sent back to the submitter. \n\nPlease click on the 'Send Back' button again and specify what needs to be changed.");
}
location.reload();
}
Everything in the Client Script section works as expected. Everything logs/alerts as it should.
My problem now lies in the Processing Script, where I've been working after a suggestion in this thread as well as a few other threads/websites. I'm trying to take the text captured from a text box on the UI Page and plug it into the comments on an approval record.
var approvalsysid = aprSysID;
var approvalcomments = approvercomment;
applycomments(approvalsysid,approvalcomments);
function applycomments(aprsysid,aprcomment) {
var aprwork = new GlideRecord('sysapproval_approver');
aprwork.addQuery('sys_id','=',aprsysid);
aprwork.query();
while(aprwork.next()){
//aprwork.comments = aprcomment; //tried but doesnt work
//aprwork.comments = 'test comment'; //tried but doesnt work
//aprwork.comments.setJournalEntry(aprcomment); //tried but doesnt work
//aprwork.comments.setJournalEntry('test comment'); //tried but doesnt work
//You might try and point out that there is no actual action here. That is on purpose for this post. All attempts that are commented out above have been tried with no luck
aprwork.update();
}
}
So I'm still stuck where I was a few days. I'm unable to write to a journal/comment field from a UI page.
If anyone can assist I'd be forever grateful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2014 06:26 AM
Just out of curiosity, if you add a gs.log statement within the while loop, does the statement write to the logs? I'm just wondering if the approval record is even found? You'll want to make sure the sys_id is actually a string when it is used in the addQuery line otherwise the query may not find the record.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2014 07:42 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2014 08:43 PM
It's a stand-alone UI page that we're developing for mobile devices. It's not at all associated with the UI Macros that are typically used for approvals nor a related list on a record, although it provides the same exact functionality as the two.
We had to go with a custom solution as the OOB mobile approval process does not work with a few custom tables we have and a few custom workflows that we use..
Everything works with the exception of the comment/journal functionality.