1

Unit Groups and Units Inside a Group

Тема: Unit Groups and Units Inside a Group

Hello,

Can you please assist on the best way to get Unit Groups and Units inside of every group, in Javascript

Looking forward

2

Unit Groups and Units Inside a Group

Re: Unit Groups and Units Inside a Group

I am using code

var params = {
        spec: [{
            "type": "type",
            "data": "avl_unit",
            "flags": 0x411,
            "mode": 0
        }]
    };
    sess.execute("core/update_data_flags", params, function(data) {
        showUnits();
    });
   

and in show units I have the following

function showUnits(){
       
    var units = sess.getItems("avl_unit");
    var unitGroups = sess.getItems("avl_unit_group");

}

with the above code, I can get all units but unitGroups is returning undefined

3

Unit Groups and Units Inside a Group

Re: Unit Groups and Units Inside a Group

core/update_data_flags request loads items from remote server to browser memory. After it you can get it through JS methods.
In your case, if you want to use unit groups you have to load them first. Like this

var params = {
        spec: [{
            "type": "type",
            "data": "avl_unit",
            "flags": 0x411,
            "mode": 0
        }, {
            "type": "type",
            "data": "avl_unit_group",
            "flags": 0x1,
            "mode": 0
       }]
    };
    sess.execute("core/update_data_flags", params, function(data) {
       console.log('Update data flags response:', data);
       showUnits();
    });

function showUnits(){
    var units = sess.getItems("avl_unit");
    var unitGroups = sess.getItems("avl_unit_group");
}