[update 1]
The short answer is: No. Cannot use flow.js to run model multiple times with 1 button click.
Thanks Naren. I use epicenter.js to do it and it worked.
[end update 1]
I tried to use operation channel publish to replace data-f-on-click. My final goal is to run model 5 times with 1 click of ‘run’ button. However after doing so, the output variable is not updated. There is no runtime error. When using operation publish channel, the variable subscribe channel are called but no data are updated. I notice if I remove ‘reset’ then the data is updated. However since I want to run it 5 times with 1 button click, I have to reset the model between each run.
code that works, time and 9 other variables in Flow.channel.variables.subscribe are updated with run result.
<button type="button" data-f-on-click="step(300)"> Step 300</button>
...
var r = [];
$(function() {
// forio flow.js
Flow.initialize({
channel: {
run: {
// the model field should already be present
model: 'wellfactory-v9.eqn',
// add the account, project, and server fields
account: 'hangingsteel',
project: 'well-factory',
server: {
host: 'api.forio.com'
}
}
}
});
console.log("Flow.initialize()");
Flow.channel.variables.subscribe([
'time',
'AggregateCostOfInventory',
'LineOfBalance[WellScoping]',
'LineOfBalance[WellPlanning]',
'LineOfBalance[Permitting]',
'LineOfBalance[SiteConstruction]',
'LineOfBalance[Drilling]',
'LineOfBalance[Completions]',
'LineOfBalance[Flowback]',
'LineOfBalance[GatheringLineConstruction]'],
function(data) {
console.log("runId:"+(runId++));
// callback is called 10 times, a time one variable is fully updated
for(var key in data) {
r[key] = data[key];
}
console.log(r);
});
Flow.channel.operations.subscribe('step',
function(data) {
console.log('step called!');
console.log(data);
});
});
code does not work,
<button type="button" onclick="run()"> Run Channel </button>
....
function run(){
console.log("run");
var runObj = { operations: [
{ name: "reset" },
{ name: "step", params:[300],
{ name: "reset" },
{ name: "step", params:[300] }
]};
Flow.channel.operations.publish(runObj);
};
time and 9 other variables in Flow.channel.variables.subscribe are NOT updated with run result.