Install package with legacy script from a JavaScript script package

XS
Ximo Serra
damal0002

Hello everyone,

I'm attempting to install a .pcg package from JavaScript, but it's not working, and I'm running out of ideas on what else to try.

A main JavaScript script is being executed, and it should install a .pcg package with a legacy sendintent script. While it works perfectly when executed from the MobiControl console on the device, encapsulating the script in a package/profile doesn't work. The sendintent from the legacy script never executes.

I've come across this post which seems to have a similar issue but no promising solution.

I based my approach on a post by Raymond Chan that provided instructions for achieving something similar, which I can't find now. He suggested creating packages to be called from other packages with a PRE-script and copying them using a file sync rule. Perhaps I misunderstood, but here's what I did:

  • Created a package with a legacy PRE-Script containing the sendintent command.
  • Copied the script to the device in an initial configuration package containing various device configuration files. This package is installed several steps before the JavaScript script is executed, so the .pcg package is in its location before being called by the script. I didn't use file sync as Ray suggested; instead, I copied it through another package. I'm not sure if this could be part of the problem.
  • The JavaScript script is executed in a package, and I've tried copying the JS code both in PRE-script and POST-script, but in both cases, I have the same problem. The JavaScript code runs correctly, but the intent is never triggered.
  • I've also tried setting a pause immediately after the mobicontrol.packages.install statement using the setTimeout(onExit, 30000) method in case the issue is that the execution of the main script ends before the second legacy script is installed, but I still haven't managed to get it to work.

I believe the code is correct because, as mentioned earlier, if I run the code from the scripts section of the web console, it works perfectly.

Am I doing something wrong? Is it possible to achieve what I'm trying to do?

Best regards.

a year ago
Android Scripting
ANSWERS
ZC
Zafer Cigdem
a year ago

Hi Ximo,

As you already mentioned the previous post (SOTI Discussion Forum), when I tested it out, i did face the same issue. And as I adviced there as an alternative option:

You may try to create a custom data as .ini file or such from your pre/post script, and based on the custom data you can create a Virtual Filter group from MobiControl Webconsole, 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 earlier tested this out and it worked. I hope it helps

Zafer

I'm still not sure if i understood correctly what you did in which order but:

1. Using packages you can create dependencies, so that a package is depending on another to be installed. With that you can create a chain of dependencies if needed.

2. Don't use javascript and legacy script in same script file, you need to seperate them.

RC
Raymond Chan Diamond Contributor
a year ago

The sets of Android script commands that are supported in different initiation use-cases (e.g. web-console send script, scheduled task profile payload, file-sync rules/policies, .pcg packages,  OOC/speed-kosk, remote-control command shell, etc.) vary slightly differently, and may also be dependent on the device agent version, enrollment mode/MDM-API, etc.

Also, based on my actual tests and production usage,  mixing legacy MobiControl scripts and javascript  are SOMETIMES possible,  I haven't figured out any well-defined patterns or rules, and extensive tests have to be tried on targeted device model(s) & device agent version(s) for each advanced script usage case.

ZC
Zafer Cigdem
a year ago

Hi @Raymond,

That would be great know how to combine both JS and legacy scripts from script side (not using a Web Console such as custom data or such as threshold/trigger mechanism). If you can share any example or idea that would help a lot. Thank you

Zafer

P
PMMOD@SOTI
a year ago