Trigger Package from MobiControl JavaScript is not working within package

Hello,

I have a solution that consists of three steps, split between two packages:

Package 1:
1. (Pre-install, Legacy) Download a .txt file from ftp.
2. (Post-install, JavaScript) Process file and identify specific row, to be used for package 2. (Verifies each row with build number and modifies a provision.xml based on it)

Package 2:
1. (Post-Install, Legacy), performing an intent, invoking the provision.xml based on result from Package 1.


The problem is that if I send all these three steps manually via "Send Script" on a device, it works flawlessly.

But when I have built it as packages in MobiControl Package Studio, everything works except the command: "mobicontrol.packages.install('/sdcard/Download/package.pcg')"

It does not give any error or anything.
And that is only when it is built in a package.

Do anyone have any ideas on how to resolve this?

Can anyone replicate the issue?
Have a package with a JavaScript post-install that starts another .pcg file.

Info on the device I have tested on;

MobiControl Version: 2024.0.0.1074
Agent på enheten: 2024.0.0.1005

Thanks in advance
2 years ago
Android Scripting
ANSWERS
ZC
Zafer Cigdem
2 years ago

 Hi Mikael,

Have you tried to use below method, if not you can try directly sending out a JS script from send script to a test device.


// Install a package and start the the embedded app as soon as the installation finishes
mobicontrol.packages.install('/sdcard/Download/package-1.pcg', onFinish);

function onFinish(result) {
    if (result.isSuccessful) {
        mobicontrol.message.createInfoDialog("After installing 1st package, it is under function now").show();
        mobicontrol.packages.install('/sdcard/Download/zafer-package-2.pcg');
    }
}



I hope it helps. Thank you

Zafer

ZC
Zafer Cigdem
2 years ago

Other than that, please also verify your first line should include JS syntax at the top of the 1st line as below:

if there is some dots or such (;) delete them and put the JS syntaxt on 1st line and re-try. 

Thank you

MA
Mikael Aspehed
2 years ago

Hi,

On your first message; the issue is that "mobicontrol.packages.install('/sdcard/Download/package-1.pcg', onFinish);" is not being executed while in a package.


And on your second; yes, the javascript itself works. The script is about 50 lines and everything else executed. It is just that one line that while being executed as a post-install, does not work. It works perfectly via "Send script to device".

Example:

  mobicontrol.log.info('Starting ProvisionerXML from Intent.');
  mobicontrol.packages.install('/sdcard/download/InstallOSUpdate.pcg');
  mobicontrol.log.info('Done');

In the above example, in a package context, the first line executes and the third one. The second one is not throwing errors, it just is not executed. And if I copy these three lines and send them via "Send script to device", it works.

But does it work for you when embedded in a package as a post-install?

ZC
Zafer Cigdem
2 years ago

Hi Mikael,

I did not test it by using a real .pcg file yesterday, I used a dummy file, and it went through inside of the function and execute the lines. I just tested it out as you said, and yes, it was not working for me as well under .pcg file for this specific command. 

If there is no feedback that we can get here, you may try to create a custom data as .ini file or such, and based on the custom data you can create a Virtual Filter group, and you can list related devices under this Virtual Group to send over this JS by using a FileSync rule from Server-to-device direction, I just tested this out and it worked. I hope it helps. Thank you

Zafer

M
MPMOD@SOTI
2 years ago