Call multiple functions in client script from script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2022 05:50 AM
I have two fields in a form. My requirement is, I've to get values selected in Business services (cmdb_ci_service) and environment(cmdb_ci_environment) field as shown below picture. Both the fields belong to different tables.
And show/populate them in another field named 'name of the account' as shown below in string format . For eg. "Business services_Environment" in this format.
For this I tried writing on change client script as below:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ba = g_form.getValue('business_services');
var ga = new GlideAjax('GetName');
ga.addParam('sysparm_name', 'getBSName');
ga.addParam('sysparm_bs', ba);
var a = ga.getXML(set_form_values);
function set_form_values(xml) {
var answer = xml.responseXML.documentElement.getAttribute("answer");
g_form.setValue('name_of_the_account', answer);
}
Script include:
var GetName = Class.create();
GetName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getBSName: function() {
var bs = this.getParameter('sysparm_bs');
var bsGR = new GlideRecord('cmdb_ci_service');
bsGR.addQuery('sys_id', bs);
bsGR.query();
if (bsGR.next()) {
var return_string = "SVC_ " + bsGR.name;
return return_string;
}
},
getEnvName: function() {
var env = this.getParameter('sysparm_env');
var envGR = new GlideRecord('cmdb_ci_environment');
envGR.addQuery('sys_id', env);
envGR.query();
if (envGR.next()) {
return envGR.name;
}
}, type: 'GetName'
});
Using above scripts I'm only getting name of business service in "name of the account field". Need help in getting both business service and environment name.
- Labels:
-
Orchestration (ITOM)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2022 06:05 AM
Hello,
Please try to write the same logic for environment field as well.
Create an on-change client script on environment field with same logic but replacing field names with environment field name .
Please accept the solution if it helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2022 06:11 AM