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

Kalai,

Thanks for your help.

The reference qualifier is working.  I'm still getting the sys_id and the destroy function still isn't working after I've swapped the order.  (I could resolve this by having an onChange Client script, but would ideally like it in one script).

Any other ideas regarding the display value?

Are you saying that this is not working? I am pretty sure that this should give you the display value of reference field.

gel('sys_display.number').value

Hi Kalai,

Apologies, it did work, I had forgotten to edit my code to populate with the new variable.

Thanks!!!!