- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2017 09:13 AM
All,
I have a requirement to add a cancel UI Action button to the RITM form that will open a window so that users can input cancel comments/reasons. Which I created and it works except for the Processing Script section of the UI Page.
I need the Processing Script to change the state & stage fields of the RITM and update the form. Which doesn't work at the moment. I have pasted my UI Page code below:
Any suggestions will help out. I haven't had to create many UI Pages within ServiceNow so I am a little stuck...
UI Page
HTML Section:
Client Script Section:
Processing Script Section:
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2017 08:12 AM
Adding Script Include for anyone that runs past this post
Scrip Include:
Make sure you mark client callable
var cancelComments = Class.create();
cancelComments.prototype = Object.extendsObject(AbstractAjaxProcessor, {
cancelRITMComments: function(){
var sc_req_item_sys_id = this.getParameter('sysparm_sys_id');
var close_comments = this.getParameter('sysparm_close_comments');
var gr = new GlideRecord("sc_req_item");
if (gr.get(sc_req_item_sys_id)) {
gr.state = 4;
gr.close_notes = close_comments;
gr.stage = 'Request Cancelled';
gr.update();
}
return true;
},
_privateFunction: function(){ // this function is not client callable
}
});
UI Page Client Script (update):
function validateComments() {
//This script is called when the user clicks "OK" in the dialog window
//Make sure there are comments to submit
var comments = gel("dialog_comments").value;
comments = trim(comments);
if (comments == "") {
//If comments are empty, alert the user and stop submission
alert("Please enter your comments before submitting.");
return false;
}
var ritm_sys_id = gel("sc_req_item_sys_id").value;
var ajaxHelper = new GlideAjax('cancelComments');
ajaxHelper.addParam('sysparm_name', 'cancelRITMComments');
ajaxHelper.addParam('sysparm_sys_id', ritm_sys_id);
ajaxHelper.addParam('sysparm_close_comments', comments);
ajaxHelper.getXMLAnswer(function(){
GlideDialogWindow.get().destroy();
});
HTML Section of UI Page (update):
<g:evaluate var="jvar_ritm_sys_id" expression="RP.getWindowProperties().get('sys_id')" />
<input type="hidden" name="sc_req_item_sys_id" id="sc_req_item_sys_id" value="${jvar_ritm_sys_id}"/>
<input type="hidden" name="selection_result" id="selection_result" value=""/>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2017 05:32 AM
Hi Brett,
The variable name in your processing script must match the name in the input field in the HTML.
Change your processing script to reference sc_req_itemSysID on line 2 and you should be good.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2017 05:50 AM
Hi Chuck,
Thank you for replying. Processing script still doesn't set fields or redirect.
Am I actually setting it right in the HTML section with this input line?
<input type="hidden" id="sc_req_itemSysID" name="sc_req_itemSysID" value="${sysparm_sysID}"/>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2017 05:59 AM
Are you passing a URL argument called sysparm_sysID?
usually when I debug UI pages, I go to System Diagnostics> Debug Log
If I want to see what variables/values are available, I include this line in my HTML
<g:breakpoint />
and in the debug output at the bottom of the screen I can see that stuff (along with any errors). You might also just dump the variable out in the open in your HTML to see if it has a value. Something like:
<p>sysparm_sysID=${sysparm_sysID}</p>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2017 08:48 AM
Hi Check,
Thanks for the debug log tip:
It looks like url arguement is just pulling the sys_id. So I updated my HTML and processing script below and still doesn't work. First time with UI Pages and I didn't think it would be this difficult.
10:38:03 AM.801: #3924 /sc_req_item.do Parameters ------------------------- sys_id=ef4373ae13123200da9fb6d96144b0f5 sysparm_record_rows=75 sysparm_record_target=sc_req_item sysparm_record_list=active=true^ORDERBYDESCdue_date sysparm_record_row=1
<input type="hidden" name="sc_req_item_sys_id" value="current.sys_id"/>
var req = new GlideRecord('sc_req_item');
//req.get(sc_req_item_sys_id);
req.get(sc_req_item_sys_id);
req.state = 4;
req.stage = 'Request Cancelled';
req.update();
var urlOnStack = GlideSession.get().getStack().bottom();
response.sendRedirect(urlOnStack);