How do I execute my XML file in JavaScript? It shows the right file to process however it is not processing the file. I think i'm missing a piece

Solved

Here is my code and the output, it shows the right file to execute but it is not processing the file.

/* global mobicontrol */
var ip = null;
mobicontrol.network.activeNetwork.ipAddresses.forEach(ipInner => {
    if (!ipInner.isLoopback && !ipInner.isLinkLocalAddress) {
        var currentIp = ipInner.hostAddress;
        const re = /^\d+\.\d+\.\d+.\d+$/;
        var isIp4 = re.test(currentIp);
        if (isIp4) {
            ip = currentIp;
            return;
        }
    }
});
var filename;
if (ip !== null) {
    var split_it = ip.split(".");
    var octet2 = ip[1];
    var serverNumber = parseInt(octet2, 10);
    switch (serverNumber) {
        // each needs to represent the service center number and associated timezone
        case 65: //ABI
        case 64: //AMA
        case 55: //AUS
        case 26: //BHM
        case 87: //BLG
        case 47: //BTR
        case 60: //CRP
        case 41: //DFW
        case 31: //DOT
        case 69: //FTS
        case 80: //FTW
        case 90: //GAR
        case 42: //HOU
        case 28: //HSV
        case 35: //JAC
        case 79: //JBO
        case 56: //JCK
        case 78: //LAF
        case 61: //LRD
        case 70: //LRK
        case 88: //LUB
        case 59: //MCA
        case 29: //MGM
            filename = '/sdcard/TimeZones/Central_TimeZone.xml';
        case 63: //ELP
            filename = '/sdcard/TimeZones/Mountain_TimeZone.xml';
        case 49: //RCO
            filename = '/sdcard/TimeZones/Atlantic_TimeZone.xml';
            
        default:
            filename = '/sdcard/TimeZones/Eastern_TimeZone.xml';
    }
} else {
    mobicontrol.log.error("Could not find the machine's IP Address defaulting to Eastern.");
    filename = '/sdcard/TimeZones/Eastern_TimeZone.xml';
}
mobicontrol.log.info('Found ' + filename + ' to sync.');
// Map the timezone to some configuration file to be downloaded.
//The time zone files will be synced prior to implementing this via soti file sync rule

a year ago
Android Scripting
ANSWERS

Do i miss something here? In your script you just  define which file to be used in the script (define the filename) but don't do anything with it.

KW
Katie Williams Bronze Contributor
a year ago

No, you did not miss anything lol, this is where I left off. This is all I have and I'm still trying to learn JS and I'm not sure how to get the files to process. I don't know how to call the files to execute it once it finds it. 

I never used it but i guess you need to use this: https://www.soti.net/mc/help/javascriptapi/en/mobicontrol.mdm.html#.configure

They use a string and not the file directly, so you may need to read the XML to a variable before processing it.

My best guess would be something like this after your code:

var fXML = new mobicontrol.io.File(filename);
var sTimeZone = fXML.readText();
mobicontrol.mdm.configure(sTimeZone);

Solution
KW
Katie Williams Bronze Contributor
a year ago

Thank you so much!! That worked! 

Nice to read and glad that i was able to help ;)

A
ABMOD@SOTI Silver Contributor
a year ago

Hi Katie Williams,

 

Thanks for posting on SOTI Pulse. Thanks, Rafael Schäfer for responding to the post, your expertise and willingness to help are greatly appreciated!

We are glad that your question is answered.