strict warning: Only variables should be assigned by reference in /home/itechpros/servoyguy.com/sites/all/modules/links/links.inc on line 1434.

How to access user properties on the Runtime

Using application.getUserProperty and application.setUserProperty don't work with Runtimes, but sometimes you need that type of functionality, so here is how you implement it.  These functions will create and store the properties in a new runtimes.properties file. These functions also uses a Global variable named globals.g_util_runtimeProperties that should be of type MEDIA.

#1. A global method to run on open of your solution to read in the properties

var type = application.getApplicationType(); 
if(type == 6) //runtime
{ 
    var runtimeProps = new Packages.java.util.Properties();
    try 
    { 
        var fis = new Packages.java.io.FileInputStream("runtime.properties");
        runtimeProps.load(fis) 
        fis.close() 
    } 
    catch(err) 
    { 
        //first time startup 
    } 
    finally 
    { 
        globals.g_util_runtimeProperties = runtimeProps 
    } 
     
}

#2. A global method to run on close of your solution to write out the properties to file

var type = application.getApplicationType(); 
if(type == 6) //runtime
{ 
    var out = new Packages.java.io.FileOutputStream("runtime.properties")
    globals.g_util_runtimeProperties.store(out, "--no comment--") 
    out.close() 
}

#3. A global method to call to get user properties. This replaces application.getUserProperty

var key = arguments[0]

var type = application.getApplicationType(); 
if(type == 6) //runtime
{ 
    return globals.g_util_runtimeProperties.getProperty(key) 
} 
else 
{ 
    return application.getUserProperty(key) 
}

#4. A global method to call to set user properties. This replaces application.setUserProperty

var key = arguments[0]
var value = arguments[1] 

var type = application.getApplicationType(); 
if(type == 6) //runtime
{ 
    globals.g_util_runtimeProperties.setProperty(key, value) 
} 
else 
{ 
    application.setUserProperty(key, value) 
}