We understand you are trying to have the facilitator loop through all the worlds, and set a variable for each world. Here’s how to do that.
// update the runs for all worlds with variables.
// parameter is map, e.g. {"var1": 10, "var2": 20}
function updateVariables(varMap) {
const wa = new F.service.World();
wa.list().then((worlds) => {
worlds.forEach((world) => {
if (world.run) {
const rm = new F.manager.RunManager(
{
run: { model: 'model.eqn'},
strategy: 'use-specific-run',
strategyOptions: {
runId: world.run
}
});
rm.getRun().then(function(run) {
rm.run.variables().save(varMap);
});
}
});
});
}
Note that the trick is to use a RunManager with the run strategy “use-specific-run”. Normally the RunManager is used to track the run for the current user, but this run strategy allows you to pass in a run. You can then get the variable service and set the value.