Call multiple functions in client script from script include

Ashwini53
Tera Contributor

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.  

find_real_file.png

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.

find_real_file.png

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.

6 REPLIES 6

Mohith Devatte
Tera Sage
Tera Sage

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

 

Shree3
Tera Expert
Hello Ashwini, Rather than going ahead with same client script, write another on-chane client script with field name as environment field. Thanks!!