Using GlideAjax from the client script in a UI page

pierrep1
Mega Guru

Hi,

I have a requirement to create a GlideDialog Window from a UI action on the case form called 'Merge'.  This window has both a reference field pointing to the case table and a multiline text field.  This is working all fine.

However the next step is to populate the close_notes (string) with the 'target' case to merge with.  I was getting undefined instead of the number of the case when trying to populate it with the value in the new 'target' field, so I am trying to use a script include to get the display value.  However, it is now populating 'GlideAjax' instead. Not sure how to pass parameters into my script include or where in the client script to put the call.  Can anyone help?:

UI script:

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">
<g:ui_form>
<!-- Get values from dialog preferences passed in -->
<table width="100%">
<tr id="description_row" valign="top">
<td colspan="2">
<!-- Short description value used as a label -->
${jvar_short_text}
</td>
</tr>
<tr>
<td>
<g:ui_reference table="sn_customerservice_case" name="number" id="number" label="short_description"/>
</td>
</tr>
<br>
</br>
<tr>
<td>
<g:ui_multiline_input_field name="reason" id="dialog_comments" label="Reason for merging case"/>
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr id="dialog_buttons">
<td colspan="2" align="right">
<!-- Pull in 'dialog_buttons_ok_cancel' UI Macro for submit/cancel buttons.
'ok' option will call the 'validateComments' Client script function from the UI Page-->
<g:dialog_buttons_ok_cancel ok="return updateFields()" ok_type="button" cancel_type="button" />
</td>
</tr>
</table>
</g:ui_form>
</j:jelly>

 

Client Script:

function updateFields(){
var reason = gel("reason").value;
var target = gel("number").value;
var trg = new GlideAjax('get_case');
trg.addParam('sysparm_name', 'getNumber');
trg.addParam('sysparm_sys_id', target);
trg.getXML(display);
function display(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
}

if(reason==""){
alert('Please populate a reason for merging cases');
return false;
}
else{
g_form.setValue('close_notes', 'merged with target record - ' + answer + ' ' + reason);
g_form.setValue('state', '7');
g_form.setValue('u_target_merge', target);
g_form.setValue('resolution_code', '8');
g_form.save();
GlideDialogWindow.get().destroy();
}
}

 

Script Include:

var get_case = Class.create();
get_case.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getNumber: function(){
var sysID = this.getParameter(sys_id);
var gr = new GlideRecord("sn_customerservice_case");
gr.addQuery("sys_id", sysID);
gr.query();
if (gr.next()) {
return gr.getDisplayValue();
}
},
type: 'get_case'

});

Cheers,

Pierre

 

1 ACCEPTED SOLUTION

1. Use this as a sample for the reference qualifier

<g:ui_reference name="my_var" query="active=true^roles=service_desk" id="u_name" table="sys_user" style="width:180px"/>

2. Try switchng the calls of destroy and save() calls. First destroy the page and do the g_form.save() next.

3. Try this for the display value of reference field from UI page

gel('sys_display.number).value

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Pierre,

So where is the code going into if or else condition?

Regards

Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

I need the result of the script include in the else (where 'answer' is):

g_form.setValue('close_notes', 'merged with target record - ' + answer + ' ' + reason);

So I have the display value in the string instead of 'undefined' or 'GlideAjax'.

Regards,

P

pierrep1
Mega Guru

function validateComments(){
var reason = gel("reason").value;

var target = gel("number").value;
alert(target);
reason = trim(reason);

if (reason == "") {
alert('Please populate a reason for merging cases');
return false;
}
//var trg = g_form.DisplayBox('number').value;
g_form.setValue('close_notes', 'Case has been merged with ' + target + ' ' + reason);
g_form.setValue('state', '7');
g_form.setValue('u_target_merge', target);
g_form.setValue('resolution_code', '8');
g_form.save();
GlideDialogWindow.get().destroy();
}

I have 3 queries.

1. How does one include a reference qualifier into the glide dialog window reference field?

2. My g_form.save() is not working

3. 'target' in the close notes is still returning the sys_id

Anyone out there got any answers to any of my queries?

1. Use this as a sample for the reference qualifier

<g:ui_reference name="my_var" query="active=true^roles=service_desk" id="u_name" table="sys_user" style="width:180px"/>

2. Try switchng the calls of destroy and save() calls. First destroy the page and do the g_form.save() next.

3. Try this for the display value of reference field from UI page

gel('sys_display.number).value