catalog item variable to display quantity of "in stock" assets where the model category is "computer

Taza
Tera Contributor

Hi all,

 

I need some help to achieve the following in a catalog item:

When a user selects a stockroom from a variable, I would like it to then calculate and display in another field the total quantity of "in stock" assets where the model category is "computer". 

 

I've been browsing the community but cannot find a definitive answer to this.

 

Please help.

2 REPLIES 2

Mani A
Tera Guru

Hi,

 

write onChange client script of selection stockroom variable

 

Client Script:
    var ga = new GlideAjax('CalAssetQuant');
    ga.addParam('sysparm_name', 'getQuant');
    ga.addParam('sysparm_stockroom', newValue); 
    ga.getXMLAnswer(function(response) {
        g_form.setValue('ENTER ANOTHER VARIABLE NAME', response);
    });

script include :

    getQuant: function() {
        var stockroom = this.getParameter('sysparm_stockroom');
        var total = 0;
        var gr = new GlideRecord('alm_asset');
gr.addEncodedQuery('model_category.name=Computer^install_status=6^stockroom='+stockroom); // 6 is in stock state 
        gr.query();
        while (gr.next()) {
            total += parseInt(gr.quantity); 
        }
        return total.toString(); 
    },

Taza
Tera Contributor

Hi Mani,

 

Thanks, I've given it a go but it doesn't work. I've attached some screenshots.

 

Any questions, please shout 😄