Need to populate the stockroom based on the selected Location on the form level

vinuth v
Tera Expert

Hi All,

 

I am working on one of the form in this form I have "Location" it is referring to cmn_location and "Stockroom" it is referring to alm_stockroom. I need to populate the stockroom based on the selected location on the form level.

 

1. on change of the location field it should be updated to only show active stockrooms associated with the selected location. On change of location the stockroom must be updated.
2. the stockroom field should be read only when the location field is empty, which will force the user to select the location field first. when not empty, the stockroom field will be editable and updated with active stockrooms only specific to the location selected.

 

OnChange of location,

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var loca = g_form.getValue('location');
    var g = new GlideAjax('locationStock');
    g.addParam('sysparm_name', 'stockroomupdate');
    g.addParam('sysparm_asset_name', loca);
    g.getXML(Displayresult);

    function Displayresult(response) {
        var result = response.responseXML.documentElement.getAttribute("answer");
        alert(result);
        g_form.setValue('stockroom', result);
       // g_form.setReadOnly('asset_id', true);

    }
}
Script Include,
var locationStock = Class.create();
locationStock.prototype = Object.extendsObject(AbstractAjaxProcessor, {
 
stockroomupdate : function(){
var result;
var stock = this.getParameter('sysparm_asset_name');
var gr=new GlideRecord('cmn_location');
gr.addQuery('sys_id',stock);
gr.query();
if(gr.next())
{
result = gr.getValue('u_default_stockroom');
}
return result;
},
 
    type: 'locationStock'
});

 

I tried with the above script I am getting all the Stockrooms.

Please any one provide me the input,

 

Thanks,

Vinutha

2 REPLIES 2

Anil Lande
Kilo Patron

Hi,

You can use onChange Client script to populate Stockroom based on selected location.

And use reference qualifier to limit the list to show stockrooms related with location.