Auto populate fields does not work on Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2021 02:04 AM
Hello I have written below onChange Client script to Auto Populate variable based on "Name"
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var caller = g_form.getReference('Name', doAlert); // doAlert is our callback function
}
function doAlert(caller) { //reference is passed into callback as first arguments
g_form.setValue('var_title', caller.title);
g_form.setValue('var_department', caller.department);
g_form.setValue('var_manager_name', caller.manager);
g_form.setValue('var_comp', caller.company);
g_form.setValue('var_location', caller.location);
var site_val = caller.location;
var loc_gr = new GlideRecord('cmn_location');
loc_gr.addQuery('sys_id', site_val);
loc_gr.query();
while (loc_gr.next()) {
g_form.setValue('var_city', loc_gr.city);
g_form.setValue('Country', loc_gr.country);
}
}
Its auto populating city and country on Fulfiller portal based on Name selected when we navigate from maintain items -> open catalog item and use try it option.
But when I check same on service portal its empty
FYI, The user form has location information and when open record for location i.e. location form has city and country information.
Kindly advice, let me know if any more information required to look into the same.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2021 10:06 AM
Hi Murthy, Thank You for the help. I tried below code it is not auto populating,
below is Onchange Catalog client script applied over Variable "Name"
and Script include Name is "Internal_Transfer"
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var Name = new GlideAjax('Internal_Transfer'); // script include name
abc.addParam('sysparm_name', 'Name'); //function name
abc.addParam('sysparm_Name', newValue); //pushing user sysID into server side
abc.getXML(callbackdata);
function callbackdata(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var push = answer.split('!'); //setting user details into variables
g_form.setValue('var_title', push[0]);
g_form.setValue('var_department', push[1], push[2]); //setting both value and display value
g_form.setValue('var_manager_name', push[3], push[4]);
g_form.setValue('var_comp', push[5], push[6]);
g_form.setValue('var_location', push[7], push[8]);
g_form.setValue('var_city', push[9]);
g_form.setValue('Country', push[10]);
}
}
Client Callable Script Include
var Internal_Transfer = Class.create();
Internal_Transfer.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserdata: function() {
var grU = new GlideRecord('sys_user');
grU.addQuery('sys_id', this.getParameter('sysparm_Name'));
grU.query();
if (grU.next()) {
return grU.title + '!' + grU.department + '!' + grU.department.getDisplayValue() + grU.manager + '!' + grU.manager.getDisplayValue() + '!' + grU.company + '!' + grU.company.getDisplayValue() + '!' + grU.location + '!' + grU.location.getDisplayValue() + '!' + grU.location.city + '!' + grU.location.country;
}
},
type: 'Internal_Transfer'
});
Am I going wrong somewhere?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2021 08:58 PM
Hi
Sorry for the late reply. Here are some Corrections
Script Include name is Correct but you given incorrect function name
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var abc= new GlideAjax('Internal_Transfer'); // script include name
abc.addParam('sysparm_name', 'getUserdata'); //function name
abc.addParam('sysparm_Name', newValue); //pushing user sysID into server side
abc.getXML(callbackdata);
function callbackdata(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var push = answer.split('!'); //setting user details into variables
g_form.setValue('var_title', push[0]);
g_form.setValue('var_department', push[1], push[2]); //setting both value and display value
g_form.setValue('var_manager_name', push[3], push[4]);
g_form.setValue('var_comp', push[5], push[6]);
g_form.setValue('var_location', push[7], push[8]);
g_form.setValue('var_city', push[9]);
g_form.setValue('Country', push[10]);
}
}
var Internal_Transfer = Class.create();
Internal_Transfer.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserdata: function() {
var grU = new GlideRecord('sys_user');
grU.addQuery('sys_id', this.getParameter('sysparm_Name'));
grU.query();
if (grU.next()) {
return grU.title + '!' + grU.department + '!' + grU.department.getDisplayValue() + grU.manager + '!' + grU.manager.getDisplayValue() + '!' + grU.company + '!' + grU.company.getDisplayValue() + '!' + grU.location + '!' + grU.location.getDisplayValue() + '!' + grU.location.city + '!' + grU.location.country;
}
},
type: 'Internal_Transfer'
});
Rest is fine.
Let me know if it helps you
Thanks
Murthy
Murthy