1

Get the list of Service Intervals of a Unit.

(18/10/2018 03:16:09 отредактировано orlo_26)

Тема: Get the list of Service Intervals of a Unit.

Hello everyone, I'm using JavaScript API.

I'm having problems to get the list of Service Intervals of a Unit. The thing is that I'm not sure if this is even possible using JS API, since the documentation about this is not provided.

I have tried to add the flag:

var flags = wialon.item.Item.dataFlag.base | wialon.item.Unit.dataFlag.maintenance;

But it doesn't help, i think is didn't exist. Do you know how I can get that list of Service Intervals?

I really really depreciate your help!!!

UPDATE:
There has been a while and I dont get answers. Please tell me if my question is not clear enogh? Or maybe it is just not possible?
Im also attaching an image that can help

  • Get the list of Service Intervals of a Unit.
2

Get the list of Service Intervals of a Unit.

Re: Get the list of Service Intervals of a Unit.

Any answer? I have the same situation, please help us.

3

Get the list of Service Intervals of a Unit.

(02/11/2018 18:04:09 отредактировано orlo_26)

Re: Get the list of Service Intervals of a Unit.

Hello Dennise, Yes I got the anser by my own after some hours of investigation. The documention provided is not complete.

This is what I found:

1- You have to add the flags of maintenance:

var flags = wialon.item.Item.dataFlag.base | wialon.item.Unit.dataFlag.lastMessage | wialon.item.Unit.dataFlag.maintenance;

2- You need to add the library to the session:

sess.loadLibrary("unitServiceIntervals");

3- Then you have to load the intervals of one unit:

var unit = sess.getItem(UNIT-ID); // get unit by id
var servs = unit.getServiceIntervals();

4- And ready! you can do what ever you want with the list on services on "servs" variable

for(var i in servs){
    alert(servs[ i ].n); // Alert with the name
}

Here you can find the information of a service object:

https://sdk.wialon.com/wiki/en/sidebar/ … aintenance

Hope this can be useful to any other person with this question! wink

4

Get the list of Service Intervals of a Unit.

Re: Get the list of Service Intervals of a Unit.

Thank you so much for this information, my friend orlo_26

5

Get the list of Service Intervals of a Unit.

Re: Get the list of Service Intervals of a Unit.

Hi guys,

Can't seem to make this work.  We have created a couple of maintenance services but still producing null output.  Are there any prerequisites for this to work besides loading the library and adding the appropriate flags?  What I'm trying to get are the maintenance service interval list indicated in here: https://sdk.wialon.com/wiki/en/sidebar/

Tried using both hosting api and js api but to no avail.  We have the appropriate permission, and even used the top account.

Any help will be very much appreciated.  Thank you.

  • Get the list of Service Intervals of a Unit.
6

Get the list of Service Intervals of a Unit.

Re: Get the list of Service Intervals of a Unit.

Hello, sg-admin !
could you please specify with which problem you faced - have you created Service intervals? Do you need to control / register?

Diana Cheley
Wialon Hosting Expert
Gurtam
7

Get the list of Service Intervals of a Unit.

Re: Get the list of Service Intervals of a Unit.

greetings, I have this example code but I answered null .. someone could develop it in javascript? or could you help me repair mine?

function msg(text) { $("#log").prepend(text + "<br/>"); }
function init() {
    var sess = wialon.core.Session.getInstance();
    var flags = wialon.item.Item.dataFlag.base | wialon.item.Unit.dataFlag.lastMessage | wialon.item.Unit.dataFlag.maintenance;
    sess.loadLibrary("unitServiceIntervals");
    sess.updateDataFlags(
    [{type: "type", data: "avl_unit", flags: flags, mode: 0}],
        function (code) {
            if (code) {
                msg(wialon.core.Errors.getErrorText(code));
                return;
            }
            var unit = sess.getItem(13459293);
            var servs = unit.getServiceIntervals();
            console.log(servs);
            for(var i in servs){
                alert(servs[ i ].n);
            }
        }
    );
}
$(document).ready(function () {
    wialon.core.Session.getInstance().initSession("https://hst-api.wialon.com");
    wialon.core.Session.getInstance().loginToken("****************************************************", "", // try to login
        function (code) {
            if (code){ msg(wialon.core.Errors.getErrorText(code)); return; }
            msg("Logged successfully"); init();
    });
});

8

Get the list of Service Intervals of a Unit.

(03/06/2019 05:36:16 отредактировано orlo_26)

Re: Get the list of Service Intervals of a Unit.

Well... I do things a little different...

First, I get all the vehicles, and create a list with them... Then I add an event to each vehicle on the list.... this event trigger a method called "selectedUnit" and it gets the list of intervals...

Getting the list of vehicles:

        function init() { // Execute after login succeed

            var sess = wialon.core.Session.getInstance(); // get instance of current Session
            // flags to specify what kind of data should be returned
            var flags = wialon.item.Item.dataFlag.base | wialon.item.Unit.dataFlag.lastMessage | wialon.item.Unit.dataFlag.maintenance | wialon.item.Unit.dataFlag.counters; 
    
            sess.loadLibrary("unitEventRegistrar");
            sess.loadLibrary("unitServiceIntervals"); //load Service Intervals

            sess.updateDataFlags( // load items to current session
                [{type: "type", data: "avl_unit", flags: flags, mode: 0}], // Items specification
                function (code) { // updateDataFlags callback
                    if (code) { msg(wialon.core.Errors.getErrorText(code)); 
                               $('.log').css('background-color', 'red'); 
                               return; 
                              } // exit if error code

                    // get loaded 'avl_unit's items  
                    var units = sess.getItems("avl_unit");
                    if (!units || !units.length){ msg("No units found");
                                                 $('.log').css('background-color', 'red');
                                                 return; 
                                                } // check if units found

                    for (var i = 0; i< units.length; i++){ // construct Select object using found units
                        var u = units[i]; // current unit in cycle
                        // append option to select /// HERE YOU NEED A <ul id="units" ></ul> on html code.
                        $("#units").append("<li value='"+ u.getId() + "' class='ui-btn ui-btn-icon-right ui-icon-check ui-li-static ui-body-inherit'>"+ u.getName()+ "</li>");
                    }

                    // bind action to select change event HERE IS WHERE YOU ADD THE EVENT TO EACH LI
                    $("#units li").click(selectedUnit);
                }
            );
        }

Now when a user clicks on a Vehicle:

        function selectedUnit(event){  
            var sess = wialon.core.Session.getInstance(); // get instance of current Session
            var unit = sess.getItem($(this).val()); // get unit by id

            //Getting Service Intervals
            var servs = unit.getServiceIntervals();

for(var i in servs){
    alert(servs[ i ].n); // Alert with the name
}

}

Hope this can be helpful for you. Note that I am using jQuery.

9

Get the list of Service Intervals of a Unit.

Re: Get the list of Service Intervals of a Unit.

thanks for your answer. Even though I use the code as you send it ... the response in console continues to be null, I do not know what I'm doing wrong

I attach my code to see if you can help me

Опубликовать вложения

Иконка вложений intervalos.txt 2.58 Кб, файл был скачан 352 раз(а) 

10

Get the list of Service Intervals of a Unit.

Re: Get the list of Service Intervals of a Unit.

I do not understand why this program gives me a response null. I already verified all the json and only that section is in null, what can I do to repair this?

function init() { // Execute after login succeed
    var sess = wialon.core.Session.getInstance(); // get instance of current Session
    // flags to specify what kind of data should be returned
    var flags = wialon.item.Item.dataFlag.base | wialon.item.Unit.dataFlag.lastMessage | wialon.item.Unit.dataFlag.maintenance | wialon.item.Unit.dataFlag.counters; 
    sess.loadLibrary("unitEventRegistrar");
    sess.loadLibrary("unitServiceIntervals"); //load Service Intervals
    sess.updateDataFlags( // load items to current session
        [{type: "type", data: "avl_unit", flags: flags, mode: 0}], // Items specification
        function (code) { // updateDataFlags callback
            if (code) { msg(wialon.core.Errors.getErrorText(code)); 
               $('.log').css('background-color', 'red'); 
               return; 
              } // exit if error code

            // get loaded 'avl_unit's items  
            var units = sess.getItems("avl_unit");
            if (!units || !units.length){ msg("No units found");
             $('.log').css('background-color', 'red');
             return; 
            }
            for (var i = 0; i< units.length; i++){ // construct Select object using found units
                var u = units[i]; // current unit in cycle
                // append option to select /// HERE YOU NEED A <ul id="units" ></ul> on html code.
                $("#units").append("<li value='"+ u.getId() + "' class='ui-btn ui-btn-icon-right ui-icon-check ui-li-static ui-body-inherit'>"+ u.getName()+ "</li>");
            }
            // bind action to select change event HERE IS WHERE YOU ADD THE EVENT TO EACH LI
            $("#units li").click(selectedUnit);
        }
    );
}
function selectedUnit(event){  
    var sess = wialon.core.Session.getInstance(); // get instance of current Session
    var unit = sess.getItem($(this).val()); // get unit by id
    //Getting Service Intervals
    var servs = unit.getServiceIntervals();
    console.log(servs);
    for(var i in servs){
        document.write(servs[ i ]); // Alert with the name
    }
}
11

Get the list of Service Intervals of a Unit.

Re: Get the list of Service Intervals of a Unit.

ozchamorrito

Try creating a new token, it looks like the token you are using has not enough privileges. I tested your code and after changing it to my own token it worked perfectly.

You should take a look here:
https://sdk.wialon.com/wiki/en/sidebar/ … rmat/token