- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2023 03:04 AM - edited 09-15-2023 03:13 AM
I have to auto populate service_offering.support_group in my incident table when business_service is selected.
Following is my script include (AutoPopulateSupportGroup):
var AutoPopulateSupportGroup = Class.create();
AutoPopulateSupportGroup.prototype = {
initialize: function() {},
populateSupportGroup: function(businessService) {
// Create a GlideRecord query to find the support group
var gr = new GlideRecord('service_offering');
gr.addQuery('name', businessService);
gr.query();
if (gr.next()) {
// Return the name of the support group
return gr.getValue('support_group');
} else {
// Return an empty string if no matching support group is found
return '';
}
},
type: 'AutoPopulateSupportGroup'
};
And this is the client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Get the selected business service
var businessService = newValue;
// Create an instance of the Script Include
var autoPopulate = new AutoPopulateSupportGroup();
// Populate the 'support_group' field with the retrieved support group
g_form.setValue('service_offering.support_group', autoPopulate.populateSupportGroup(businessService));
}
How ever I get this error when I choose the value for the business_service .
onChange script error: ReferenceError: AutoPopulateSupportGroup is not defined function () { [native code] }
What am I doing wrong?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2023 04:19 AM - edited 09-15-2023 04:20 AM
Hi @vidhya_mouli,
Script Include:
var populateaddress = Class.create();
populateaddress.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
demo: function() {
var id= this.getParameter('sysparm_company');
var gr = new GlideRecord('service_offering');
gr.addQuery('sys_id', id);
gr.query();
if (gr.next()) {
var ans = gr.support_group;
return ans;
}
},
type: 'populateaddress'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('populateaddress');
ga.addParam('sysparm_name', 'demo');
var com = g_form.getValue('business_service');
ga.addParam('sysparm_company', com);
ga.getXML(callBackFunction);
function callBackFunction(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('support_group', answer);
}
}
Please mark this answer as correct and helpful if it solves your issue.
Regards,
Siva Jyothi M.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2023 03:26 AM
You are trying to communicate from Client Side to Server Side - please try using GlideAjax.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2023 03:58 AM - edited 09-15-2023 06:28 AM
@vidhya_mouli First of all, you need to use GlideAjax to call server side script include inside the client script.
var ga = new GlideAjax('HelloWorld');
Secondly, you need to specify the method name while making the Ajax call as follows.
ga.addParam('sysparm_name','helloWorld');
You need to specify the parameter to pass inside the helloWorld method as follows.
ga.addParam('sysparm_user_name',"Bob"); // Set parameter sysparm_user_name to 'Bob'
Here is how you should process the response.
ga.getXML(HelloWorldParse); /* Call HelloWorld.helloWorld() with the parameter sysparm_user_name set to 'Bob'
and use the callback function HelloWorldParse() to return the result when ready */
// the callback function for returning the result from the server-side code
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2023 04:19 AM - edited 09-15-2023 04:20 AM
Hi @vidhya_mouli,
Script Include:
var populateaddress = Class.create();
populateaddress.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
demo: function() {
var id= this.getParameter('sysparm_company');
var gr = new GlideRecord('service_offering');
gr.addQuery('sys_id', id);
gr.query();
if (gr.next()) {
var ans = gr.support_group;
return ans;
}
},
type: 'populateaddress'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('populateaddress');
ga.addParam('sysparm_name', 'demo');
var com = g_form.getValue('business_service');
ga.addParam('sysparm_company', com);
ga.getXML(callBackFunction);
function callBackFunction(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('support_group', answer);
}
}
Please mark this answer as correct and helpful if it solves your issue.
Regards,
Siva Jyothi M.