Client script sysparm GlideAjax return value of parameter

Juampi
Tera Contributor

Hi Community. 

I'm trying to send a parameter from client script to script include. This parameter would be the field I wanna get but I don't know how to indicate to script include to return the value of the field.

In summary, I am trying to create a GlideAjax that receives as a parameter any field that you want from which you want to obtain its value.

I have the next code 

//Client script 

 

function onChange(control, oldValue, newValue, isLoading) {
     if (isLoading || newValue == '') {
     return;
}

var ga = new GlideAjax('testSC');
ga.addParam('sysparm_name', 'getUserInfo');
ga.addParam('sysparm_sysidUser', newValue);
ga.addParam('sysparm_field','department');  // In this case this is the field I want to get 
ga.getXML(responseCallBack);

}

function responseCallBack(response) {
    var data = response.responseXML.documentElement.getAttribute('answer');
    alert(data);
}

//Script Include

 

 

var testSC = Class.create();
testSC.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserInfo: function() {

var userId = this.getParameter('sysparm_sysidUser');
var field = this.getParameter('sysparm_field'); 
var gr = new GlideRecord('sys_user');

gr.addQuery('sys_id', userId);
gr.query();

if (gr.next()) {
return gr.?????; //Here is the problem how I can return the value of the field passed as a parameter in this case the parameter store in "field" variable 
}

},
type: 'testSC'
});

 

Thanks a lot 

 

1 ACCEPTED SOLUTION

Voona Rohila
Giga Patron
Hi Juampi

You want to return the value of the particluar field you are passing right? If not please provide more details.

 

var testSC = Class.create();
testSC.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserInfo: function() {

var userId = this.getParameter('sysparm_sysidUser');
var field = this.getParameter('sysparm_field'); 
var gr = new GlideRecord('sys_user');

gr.addQuery('sys_id', userId);
gr.query();

if (gr.next()) {
gs.info("Test :"+gr.getValue(field.toString()));//test it.
return gr.getValue(field.toString());

},
type: 'testSC'
});

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

2 REPLIES 2

Voona Rohila
Giga Patron
Hi Juampi

You want to return the value of the particluar field you are passing right? If not please provide more details.

 

var testSC = Class.create();
testSC.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserInfo: function() {

var userId = this.getParameter('sysparm_sysidUser');
var field = this.getParameter('sysparm_field'); 
var gr = new GlideRecord('sys_user');

gr.addQuery('sys_id', userId);
gr.query();

if (gr.next()) {
gs.info("Test :"+gr.getValue(field.toString()));//test it.
return gr.getValue(field.toString());

},
type: 'testSC'
});

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Thank you very much is what I was looking for.