Need to return multiple value from Script incldue to client script

nkumari
Tera Contributor

Script include to return CI number and support group manager name. But it is not returning value

 

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

getApplicationDetails: function() {

var application_name = this.getParameter('sysparm_id');
var result;
var grApplication = new GlideRecord('cmdb_ci_service_discovered');
grApplication.addQuery('sys_id', application_name);
grApplication.query();

if (grApplication.next()) {

var appobje = {};
appobje.num = grApplication.u_business_app.u_number.toString();
appobje.senmanger = grApplication.support_group.u_senior_manager.toString();
}
return JSON.Stringfy(appobje);

},

type: 'applicationIDPopulation'
});

 

Client Script:

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

//Type appropriate comment here, and begin script below
var ga = new GlideAjax('applicationIDPopulation');
ga.addParam("sysparm_name", "getApplicationDetails");
ga.addParam("sysparm_id", g_form.getValue('application_id'));
ga.getXML(getResponse);
function getResponse(response) {

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

var result = JSON.parse(answer);


g_form.addInfoMessage( g_form.getValue('application_id'));

g_form.setValue('populate_application_id', result.num);
g_form.setValue('u_level_approval', result.senmanger);

}
}

1 ACCEPTED SOLUTION

Namrata Ghorpad
Mega Sage
Mega Sage

Hello In script include inside if change the code like below

if (grApplication.next()) {

var appobje = {};
appobje.num = grApplication.u_business_app.u_number.toString();
appobje.senmanger = grApplication.support_group.u_senior_manager.toString();
return JSON.stringfy(appobje);
}


},

 Regards,

Namrata 

View solution in original post

5 REPLIES 5

Anil Lande
Kilo Patron

Hi,

I guess the issue is with return statement in Script Include: 

return JSON.Stringfy(appobje);

It should be

return JSON.stringify(appobje);  //stringify is in small letters

 

 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

correct answer and helpful

Namrata Ghorpad
Mega Sage
Mega Sage

Hello In script include inside if change the code like below

if (grApplication.next()) {

var appobje = {};
appobje.num = grApplication.u_business_app.u_number.toString();
appobje.senmanger = grApplication.support_group.u_senior_manager.toString();
return JSON.stringfy(appobje);
}


},

 Regards,

Namrata 

In continuation to this.

In client script (on change, variable : Application) if senmanager value is blank it should return 'Requested For' Manager name.

 

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


//Type appropriate comment here, and begin script below
var ga = new GlideAjax('applicationIDPopulation');
ga.addParam("sysparm_name", "getApplicationDetails");
ga.addParam("sysparm_id", g_form.getValue('application_id'));
ga.getXML(getResponse);

function getResponse(response) {

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

var result = JSON.parse(answer);

g_form.addInfoMessage(g_form.getValue('application_id'));

g_form.setValue('populate_application_id', result.num);
g_form.addInfoMessage(result.senmanger);

if (result.senmanger != '') {

g_form.setValue('u_level_approval', result.senmanger);
} else if (result.senmanger == '') {

var id = g_form.getValue('request_for');

var user = new GlideRecord('sys_user');
user.addQuery('sys_id',id);
user.query();
if (user.next()) {
g_form.setValue('u_level_approval', user.manager);
}
}


}

}