How to get value from server side to client side

megana1
Kilo Contributor

I have field :Laptop of check Box in catalog Item table .

The value of this need to populate on variable select Laptop.

To achieve this i wrote script include of client callable but i receive Null value ,i don't understand where the mistake happens.

function onLoad() {

var sysid =g_form.getUniqueValue('cat_item');

//var value =g_form.getParameter("sysparm_id");

alert('item'+sysid);

var grtest= new GlideAjax('LaptopValueCheck');

grtest.addParam('sysparm_function','laptopValue');

grtest.addParam('sysparm_desk',sysid);

grtest.getXML(makeVariablesSelect);

}

function makeVariablesSelect(response) {

var answer = response.responseXML.documentElement.getAttribute("answer");

alert(answer);

if(answer =='true') {

g_form.setValue('select_laptop,true);

}else{

g_form.setValue('select_laptop',false);

}

}

Script Include :

var LaptopValueCheck = Class.create();

DeskSharingValueCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {

laptopValue: function(){

var item=this.getParameter('sysparm_desk');

gs.log('item'+item);

var gr=new GlideRecord('sc_cat_item');

gr.get(item);

if(gr.u_laptop)

{

return gr.u_laptop;

}

else{

return false;

}

},

});

1 ACCEPTED SOLUTION

Jon Barnes
Kilo Sage

instead of sysparm_function, use sysparm_name when passing the function name into GlideAjax.



Also, if you use g_form.getUniqueValue, it won't give you the value of a variable. generally this is used to give you the sys_id of the record you are on currently. So if you want the value of your laptop field there, use g_form.getValue('field_name'), or if this is an onchange script, then you can use newValue, which should already be passed into the client script for you.


View solution in original post

2 REPLIES 2

Jon Barnes
Kilo Sage

instead of sysparm_function, use sysparm_name when passing the function name into GlideAjax.



Also, if you use g_form.getUniqueValue, it won't give you the value of a variable. generally this is used to give you the sys_id of the record you are on currently. So if you want the value of your laptop field there, use g_form.getValue('field_name'), or if this is an onchange script, then you can use newValue, which should already be passed into the client script for you.


Thanks Jon it works.



But i would like to know why sysparm_function,doesn't work.