How to access/fetch field value in client script which is mapped from other table

Jay N
Tera Contributor

Hi experts,

 

I have 3 string fields Location, Platform.Platform Type and Platform.Platform SubType on a table Platform matrix and the data is loaded through transform maps.

 

As per the requirement I have configured theses 3 to another custom table form view.

Platform.Platform Type is Dependent on Location,

Platform.Platform SubType  is Dependent on Platform.Platform Type.

 

Now I need to add the choices under these 3 fields dynamically fetching values from 'Platform matrix' table, when the location is changed on the form.

 

How to access the fields Platform Type and Platform SubType (on client script) which are coming from another table.

 

Platform matrix table

JayN_0-1668417172760.png

Custom form:

JayN_1-1668417190310.png

 

Thanks, Jay

 

 

3 REPLIES 3

Theo BOULANGER
Giga Guru

Hello @Jay N ,

 

You'll need a script include callable from client side,

Please check technical names because you don't provide it.

 

ScriptInclude :

getLocationFields: function(){
    var result = {};
    var location = this.getParameter('sysparm_location');

    var ga = new GlideRecord('your platform matrix table's name);
    ga.addEncodedQuery('location=' + location);
    ga.quert();

    if(ga.next()) {
        result.platformType = ga.platform_type;
        result.platformSubType = ga.platform_sub_type;
    }

    return JSON.stringify(result);

}
 
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
       return;
    }
 
     var gat = new GlideAjax("yourApp.getLocationFields");
     gat.addParam("location", g_form.getValue('location'));
     gat.getXML(showMessage);
 
 
 }
 
 function showMessage(response) {
     var answer = response.responseXML.documentElement.getAttribute("answer");
     g_form.setValue("platform_type", answer.platformType);
     g_form.setValue("platform_sub_type", answer.platformSubType);
  }
 
 
Maybe you will need a JSON parse because for multiple return I had to do it, or you're free to do 2 functions and apply it in your client script with two different glideAjax.
 
Regards,

 

Thanks Theo for quick response, will try your solution.

Tell me if it worked or the error if there's one