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});
   });

Constructor options

Required? Name Type Description
Yes runService RunService The run service instance to which the variable filters apply.

Methods

load(variable[, outputModifier, options])

Get values for a variable.

Parameters

Required? Name Type Description
Yes variable string Name of variable to load.
  outputModifier {"startRecord":["number"],"endRecord":["number"],"sort":["string"],"direction":["string"]} Available fields include: startrecord, endrecord, sort, and direction (asc or desc).
  options object Overrides for configuration options.

Example

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

query(query[, outputModifier, options])

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

Parameters

Required? Name Type Description
Yes query Object / Array The names of the variables requested.
  outputModifier {"startRecord":["number"],"endRecord":["number"],"sort":["string"],"direction":["string"]} Available fields include: startrecord, endrecord, sort, and direction (asc or desc).
  options object Overrides for configuration options.

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'] });

save(variable[, val, options])

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.)

Parameters

Required? Name Type Description
Yes 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 If passing a string for variable, use this argument for the value to save.
  options object Overrides for configuration options.

Example

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