Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Unable to use GlideAjax in UI page of servicenow

Siba2
Kilo Contributor

Dear Team,

I am unable to use GlideAjax in my UI page. I am struggling on the UI to send information and get back result from database table via scripting.

 

I have developed HTML for UI page and in client script I am using Glide Ajax to use script include and return the result. Not sure if  glide ajax is working. Appreciate advise from the Developer network, I am very new to Service now.

 

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">

Candidate Id <input type = "text" id = 'cand' > </input>
<button id = 'search' type = "submit" onClick="startSearch()" > Search </button>

</j:jelly>

 

CLIENT SCRIPT:

//alert("hello , Iam on client script");
//document.getElementById("cand").value = "My value";

//jQuery("#cand").val("okok");

function startSearch()
{
//var cand_id = g_form.getValue(cand);
//var one = g_form.getDisplayBox('cand');
//alert(cand_id);

var ok1 = jQuery("#cand").val();
//alert(ok1);
//alert(ok1);
var ga = new GlideAjax('u_get_name');//name of script include
a.addParam('sysparam_name','getCandDetails');//calsl teh respective function in scritp include
ga.addParam('sysparm_cand', ok1);//name of function on script include
ga.getXML(candNameSearch);

}


function candNameSearch(response) {

var answer = response.responseXML.documentElement.getAttribute("answer");
answer = answer.evalJSON(); //Transform the JSON string to an object

g_form.setValue('cand',answer);


}

 

SCRIPT INCLUDE(u_get_name)

var u_get_name = Class.create();
u_get_name.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

getCandDetails:function(){
alert('reached scritp include');
var retVal; // Return value

var cand1 = this.getParameter('sysparm_cand');

var cand_table = new GlideRecord('candidate_master');//table where desired variable lives

cand_record.addQuery('candidate_id',cand1);

cand_table.query();

// Query user records

if(cand_table.next())

{

retVal = cand_table.candidate_name;//name of field with info you want to grab

}

return retVal;

},

type: 'u_get_name'
});

 

Regards,

Sibananda

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

Please check below useful resources for working with UI pages glideajax.

http://aqibnow.com/2014/glide-ajax-1/

https://stackoverflow.com/questions/41447692/servicenow-ui-page-glideajax

 

Regards,

Sachin

View solution in original post

1 REPLY 1

sachin_namjoshi
Kilo Patron
Kilo Patron

Please check below useful resources for working with UI pages glideajax.

http://aqibnow.com/2014/glide-ajax-1/

https://stackoverflow.com/questions/41447692/servicenow-ui-page-glideajax

 

Regards,

Sachin