Script to rename Android Enterprise devices

ML
Matt Ladwig
AbeTech Inc

I am looking for a way to rename a device with a user specified name.  I would like to prompt the user for the asset number and then use that in the device name.  I got that information with a Java script:

var file = new mobicontrol.io.File('/sdcard/asset.txt');

mobicontrol.message.createTextPromptDialog('What is the asset tag number?')
.withCallback(onOk).show();

function onOk(result) {
if (result.inputText != null) {
file.writeText(result.inputText);
}
}

But when I try to use that information to rename the device I get an error saying Set isn't a valid command:

set myVar=TXT:/sdcard/asset.txt?LN=1

devrename %myVar%

Is there a way to either do this all in 1 Java script command?  Or is there a way to set the variable from the legacy script?

4 years ago
MobiControl - Android Script Engine
ANSWERS
RS
Rafael Schäfer
4 years ago

So, if i understand you correct, the only problem is to get the entered value from the file right?

1. I think you forgot one / -> set myVar=TXT://sdcard/asset.txt?LN=1

I never used that but saw this in the example.

There could be a workaround:

Create a Custom data which reads this from the txt file on the device (but in my opinion .ini would be better to handle).

Then you can use this to rename the device (a checkin between entered data and data to be collected could be needed to provide the data to the console).

Then the command would be a bit different:

devrename "%MCCustomData:Your custom data name%"

 
RC
Raymond Chan Diamond Contributor
4 years ago (edited 4 years ago)

Hi Matt,

You just can't mix javascript commands with legacy script command in the same script file, and expect the script engine (javascript engine in your case) in the device agent  to run the whole script properly.

ML
Matt Ladwig
4 years ago

There could be a workaround:

Create a Custom data which reads this from the txt file on the device (but in my opinion .ini would be better to handle).

Then you can use this to rename the device (a checkin between entered data and data to be collected could be needed to provide the data to the console).

Then the command would be a bit different:

devrename "%MCCustomData:Your custom data name%"

Thanks Rafael,  This is what I ended up doing.  Would be so much simpler if the Java script had the capability to rename the device.