Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

How can we populate data on form based on current selection of 4 values, all are in different tables

DevanshT
Tera Contributor

I have a table "A", in that 4 fields are reference from table "B"

and there is one more table "C".

 

From this table C, I want a reference field to auto populate based on current selection of values at form of A

The field names in  B and C have common label names but backend names are different.

 

I tried using GlideAjax script include + Client Script - Its NOT working

I tried g_scratchpad along with a business rule - Its NOT working

 

Is there any other way by which this can be achieved.

4 REPLIES 4

Sandeep Rajput
Tera Patron

@DevanshT Ideally, you should be able to do it via GlideAjax script include + onChange Client Script. Could you please share the client script and Server side script to see if there are any syntactical errors. 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) return;
 
    var modelYear = g_form.getValue('model_year');
    var brand = g_form.getValue('brand');
    var commercialName = g_form.getValue('commercial_name');
    var affectedProductCode = g_form.getValue('affected_product_code');
 
    if (!modelYear || !brand || !commercialName || !affectedProductCode) {
        g_form.clearValue('reference_budget_lean_volume');
        return;
    }
 
    var ga = new GlideAjax('FinanceVolumeAJAX');
    ga.addParam('sysparm_name', 'getFinanceVolume');
    ga.addParam('sysparm_model_year', modelYear);
    ga.addParam('sysparm_brand', brand);
    ga.addParam('sysparm_commercial_name', commercialName);
    ga.addParam('sysparm_affected_product_code', affectedProductCode);
 
    ga.getXMLAnswer(function(answer) {
        if (answer) {
            g_form.setValue('reference_budget_lean_volume', answer);
        } else {
            g_form.clearValue('reference_budget_lean_volume');
        }
    });
}
 
 
 
 
 
 
 
var FinanceVolumeAJAX = Class.create();
FinanceVolumeAJAX.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
 
    getFinanceVolume: function () {
 
        var modelYear = this.getParameter('sysparm_model_year');
        var brandVM = this.getParameter('sysparm_brand');
        var commercialVM = this.getParameter('sysparm_commercial_name');
        var productVM = this.getParameter('sysparm_affected_product_code');
 
        if (!modelYear || !brandVM || !commercialVM || !productVM) {
            return '';
        }
 
       
        var brandGR = new GlideRecord('x_fich_evolution_0_vehicle_mapping');
        if (!brandGR.get(brandVM)) return '';
        var actualBrand = brandGR.getValue('brand');
 
       
        var commercialGR = new GlideRecord('x_fich_evolution_0_vehicle_mapping');
        if (!commercialGR.get(commercialVM)) return '';
        var actualCommercialName = commercialGR.getValue('commercial_name');
 
       
        var productGR = new GlideRecord('x_fich_evolution_0_vehicle_mapping');
        if (!productGR.get(productVM)) return '';
        var actualProductCode = productGR.getValue('affected_product_code');
 
       
        var fvGR = new GlideRecord('x_fich_evolution_0_finance_volume');
        fvGR.addQuery('gn_volume_year_name', modelYear);
        fvGR.addQuery('gn_brand_name', actualBrand);
        fvGR.addQuery('gn_model_name', actualCommercialName);
        fvGR.addQuery('cd_car_line_engineering_model_code', actualProductCode);
        fvGR.setLimit(1);
        fvGR.query();
 
        if (fvGR.next()) {
            return fvGR.getUniqueValue();
        }
 
        return '';
    },
 
    type: 'FinanceVolumeAJAX'
});
 

Ankur Bawiskar
Tera Patron

@DevanshT 

so what debugging did you do in your scripts?

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

All I understood is that model year backend name is different in both tables and thats why it might not fetch the values correctly.