populate multiple fields on a catalog form from the same script include

alexm1
Tera Contributor

Hello,

I have a script include which has multiple functions, like this:

getFolder:function(){

var app = this.getParameter('sysparm_app');
var gr = new GlideRecord('u_shared_folder_list');
gr.addQuery('sys_id',app);
gr.query();
if(gr.next())
{
return gr.getDisplayValue("u_ucn_path");
}
},
getLocation:function(){
//do stuff
},
getBusiness:function(){
//do stuff
}
},

I would like to call each function from a catalog client script and populate corresponding fields on a service catalog form.

I have a reference field called Folder to the custom table u_shared_folder_list, and some single line of text fields named Business Location and Path. When I choose a value under folder the other  fields should be populated with the corresponding business location value and path values

For example, getBusiness function should populate a field called Business, getLocation should populate a field called Location and so on. 

Thanks,

1 ACCEPTED SOLUTION

Munender Singh
Mega Sage

Hi,

I have used this method to pass user's location and manager in an array on script include and setting the caller's manager and location on the incident form.

Hope this would help you out.

Script include:

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

getDetails: function() {

//Get the sys_ID for the call

//pass the input
var callerSysID = this.getParameter('sysparm_callerSysID');

//glide the user table for fetching the records
var gr = new GlideRecord('sys_user');
gr.get(callerSysID);

// var mgr = gr.getDisplayValue('manager');
// var loc = gr.getDisplayValue('location');
var mgr = gr.getValue('manager');
var loc = gr.getValue('location');

var arr = []; // define the array
arr[0] = mgr; //set the manager in the array
arr[1] = loc; //set the location in the array

return JSON.stringify(arr);
},


type: 'callerDetails'
});

 

Client script:

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

var callerSysID = g_form.getValue('caller_id'); //push the sysID of the caller record

var ga = new GlideAjax('callerDetails'); //call the script include
ga.addParam('sysparm_name','getDetails'); // call the function of include
ga.addParam('sysparm_callerSysID', callerSysID); //pass the fetched call sys_id in the include
ga.getXML(handleResponse);

function handleResponse(response){

var answer = response.responseXML.documentElement.getAttribute("answer"); //fetch the response from script include

var answers = answer.evalJSON(); //evaluate the response and decode it
alert(answer);
g_form.setValue('u_manager',answers[0]); //set the short description
g_form.setValue('u_location',answers[1]); //set te description

}


}

 

Regards,

Munender

 

View solution in original post

2 REPLIES 2

Harsh Vardhan
Giga Patron

Adding one thread here.

kindly check that.

 

GlideAjax call multiple functions

Munender Singh
Mega Sage

Hi,

I have used this method to pass user's location and manager in an array on script include and setting the caller's manager and location on the incident form.

Hope this would help you out.

Script include:

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

getDetails: function() {

//Get the sys_ID for the call

//pass the input
var callerSysID = this.getParameter('sysparm_callerSysID');

//glide the user table for fetching the records
var gr = new GlideRecord('sys_user');
gr.get(callerSysID);

// var mgr = gr.getDisplayValue('manager');
// var loc = gr.getDisplayValue('location');
var mgr = gr.getValue('manager');
var loc = gr.getValue('location');

var arr = []; // define the array
arr[0] = mgr; //set the manager in the array
arr[1] = loc; //set the location in the array

return JSON.stringify(arr);
},


type: 'callerDetails'
});

 

Client script:

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

var callerSysID = g_form.getValue('caller_id'); //push the sysID of the caller record

var ga = new GlideAjax('callerDetails'); //call the script include
ga.addParam('sysparm_name','getDetails'); // call the function of include
ga.addParam('sysparm_callerSysID', callerSysID); //pass the fetched call sys_id in the include
ga.getXML(handleResponse);

function handleResponse(response){

var answer = response.responseXML.documentElement.getAttribute("answer"); //fetch the response from script include

var answers = answer.evalJSON(); //evaluate the response and decode it
alert(answer);
g_form.setValue('u_manager',answers[0]); //set the short description
g_form.setValue('u_location',answers[1]); //set te description

}


}

 

Regards,

Munender