forio Toggle navigation

Variables API Service

Used in conjunction with the Run API Service to read, write, and search for specific model variables.

var rm = new F.manager.RunManager({
      run: {
          account: 'acme-simulations',
          project: 'supply-chain-game',
          model: 'supply-chain-model.jl'
      }
 });
rm.getRun()
  .then(function() {
     var vs = rm.run.variables();
     vs.save({sample_int: 4});
   });

Configuration Options

runService

  • runService

The runs object to which the variable filters apply. Defaults to null.

Methods

load

Get values for a variable.

Example

 vs.load('sample_int')
     .then(function(val){
         // val contains the value of sample_int
     });

Parameters

  • variable: String Name of variable to load.

  • outputModifier: Object (Optional) Available fields include: startrecord, endrecord, sort, and direction (asc or desc).

  • options: Object (Optional) Overrides for configuration options.

query

Returns particular variables, based on conditions specified in the query object.

Example

 vs.query(['price', 'sales'])
     .then(function(val) {
         // val is an object with the values of the requested variables: val.price, val.sales
     });

 vs.query({ include:['price', 'sales'] });

Parameters

  • query: Object|Array The names of the variables requested.

  • outputModifier: Object (Optional) Available fields include: startrecord, endrecord, sort, and direction (asc or desc).

  • options: Object (Optional) Overrides for configuration options.

save

Save values to model variables. Overwrites existing values. Note that you can only update model variables if the run is in memory. (An alternate way to update model variables is to call a method from the model and make sure that the method persists the variables. See do, serial, and parallel in the Run API Service for calling methods from the model.)

Example

 vs.save('price', 4);
 vs.save({ price: 4, quantity: 5, products: [2,3,4] });

Parameters

  • variable: Object|String An object composed of the model variables and the values to save. Alternatively, a string with the name of the variable.

  • val: Object (Optional) If passing a string for variable, use this argument for the value to save.

  • options: Object (Optional) Overrides for configuration options.