- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2015 09:02 AM
Hi there
In order to Reject Approval from a Context Menu, I have created a ui action which then calls a ui page (with client script included) and displays a dialog box, however when I click 'Ok' on the dialog box I'd like the text that was entered into the dialog box to copy into the comments box in the approval form. Can't figure out how to do this? Ideas welcome 🙂
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2015 03:52 AM
UI action script: (Just add the line in bold)
function popupRejectApproval() {
var gdw = new GlideDialogWindow('reject_request');
gdw.setTitle('Reject this Request');
gdw.setPreference("selectedRecord",rowSysId);
gdw.render();
}
UI page client script:
function validateComments() {
var selectedRecord = "${RP.getWindowProperties().get('selectedRecord')}";
var dialcoms = gel("dialog_comments").value;
var comments = trim(dialcoms);
if (comments == "") {
alert("Comments are mandatory for rejection");
return false;
}
var getApproverRecord = new GlideRecord('sysapproval_approver');
if(getApproverRecord.get(selectedRecord))
{
getApproverRecord.comments=comments;
getApproverRecord.state='rejected';
getApproverRecord.update();
}
GlideDialogWindow.get().destroy(); //Close the dialog window
}
Note: Change the querying part to a glideajax. Once the record is updated, redirect to the record you want else the screen will appear as static making you believe that the update has not happened.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2015 09:41 AM
I did something similar with a UI action. My comments were going to a string field, not a journaled field, but I think it would work anyway (Using Journal Fields - ServiceNow Wiki ).
My UI action was set up like this:
Name: Return Reason
Client: true
Onclick: getAReason()
function getAReason(){
var confirmation = prompt('Please enter a comment on why you are returning the Time Card:', '');
//Clicking Cancel on the pop up box returns null, and clicking OK returns whatever was in the box, which could be an empty string.
//We don't want either of these things to cause a submission.
if (confirmation !== null && confirmation != '') {
table.field = confirmation;
card.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2015 09:52 AM
g_form.setValue can be used to set values to the fields of the table. I have done this in the past.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2015 10:05 AM
This is used in one of my UI page and it gets called on click of OK button
function showDescription()
{
g_form.setValue('description',gel('userInput').value);
GlideDialogWindow.get().destroy();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2015 09:33 AM
Seems like you have the right solution but I can't quite figure out how to word it - not a developer or even very familiar with scripting of any kind unfortunately. Below is the UI Action and the UI Page, if you have any idea what I need to add to the page and where I'd be grateful:
__________________________________
UI Action:
Name: Reject
Table: Approval
Action name: reject_approval
Update & Client ticked
Onclick: popupRejectApproval()
Condition: gs.hasRole('itil') || isApprovalMine(current) && current.state == 'requested'
Script:
function popupRejectApproval() {
var gdw = new GlideDialogWindow('reject_request');
gdw.setTitle('Reject this Request');
gdw.render();
}
_______________________________________
UI Page:
Name: reject_request
HTML
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
Comments are mandatory for rejection:
<textarea name="dialog_comments" id="dialog_comments" style="width: 100%;">
</textarea>
<g:dialog_buttons_ok_cancel ok="return validateComments()" ok_type="button" cancel_type="button" />
</j:jelly>
Client Script
function validateComments() {
//This script is called when the user clicks "OK" in the dialog window
var dialcoms = gel("dialog_comments").value;
comments = trim(dialcoms);
if (comments == "") {
//If comments are empty, alert the user and stop submission
alert("Comments are mandatory for rejection");
return false;
}
GlideDialogWindow.get().destroy(); //Close the dialog window
}
_______________________________________________________________________