Javascript result as CUSTOM Data

In a previous post I found how to create an ini file on the app version from a certain app.

javascript:

var app = mobicontrol.app.getInstalledApp('com.sygic.fleet');
var appVersion = app.versionName
var data = '[DATA]\nVERSION=' + appVersion;
var file = new mobicontrol.io.File('/sdcard/sygicappVersion.ini');
file.writeText(data);

Which gives me an ini file with this data:

[DATA]
VERSION=22.3.9

Problem is I'm stuck on how to get this as a custom data field ?

Anyone who can help me on this one ?

2 years ago
SOTI MobiControl
ANSWERS
MD
Matt Dermody
2 years ago

Based on your ini file format the section name should be DATA and the value name should be VERSION. I also am not sure that will be registered as an Integer type. You may need to have the value read in as a String.

RS
Rafael Schäfer
2 years ago

Fully agree to what Matt wrote here and in your script in the second line a ; is missing.

And to add as well, you can usu ini functions in javascript instead of doing text operations. Example:

var ini = require('ini');
var iniFile = new mobicontrol.io.File('/Path/Filename.ini');
if (!iniFile.exists) {
    iniFile.createFile();
}
var config = ini.parse(iniFile.readText());
config.Section1= { Key1: 'Value' };
config.Section2= { Key2: 'Value' };
config.SectionN= { KeyN: 'Value' };
iniFile.writeText(ini.stringify(config));
T
TimBel
2 years ago

Hi Matt, 

this seemed to work indeed, many thx for the help !

@Rafael: what do you mean by on the second line a is missing ? 
Script seems to work fine 

RS
Rafael Schäfer
2 years ago

in your script there is a missing ; at the end in line 2:

var appVersion = app.versionName;
A
Aaron
2 years ago

I used your JS to query an app's version and save it as a file, I then used the following custom data settings and it was able to read the file and display the info.

T
TLMOD@SOTI
2 years ago

Hi TimBel,

Thanks for posting on SOTI pulse. Thanks Matt and Rafael for responding to the post, your expertise and willingness to help are greatly appreciated!

Has your query been resolved? If not, or if you have any additional concerns, please don't hesitate to reach out. We are dedicated to providing assistance and support.

Also, if this post has helped you in solving your query, I would request you to mark the particular comment as "is solution", so that others may benefit from this information.

Kind Regards,