Not able to access Vensim Model variable using Model Variable API

Hi,

I am trying to access the variable “TeamWeightage” inside the vensim model through Model Variable API.
When I set up a new run, I can get its value. However, while developing, when I am trying to fetch its value multiple times, it gives the 410 (Gone) error and so the simulation breaks.

Please tell me how to resolve this issue.

Thank You.

Regards,
Kenil Patel

Hi, I have the same problem. Have you managed to solve it?

Dear Kenil,

The issue is that the variables are not being saved to the database, so they are only available while the model run is loaded into memory. This is due to a missing context file which would specify which variables to save.

More specifically. When a run is started it’s loaded into memory. All variables are available for the page to display. After a certain amount of idle time (typically 30 minutes, but this is configurable), the run will leave memory and the variables will not be available.

However, if the variables are listed in the context file (*.ctx2) with the save property, then they are saved into the database. Not all variables are saved, just the ones listed. Those variables are available to the user or facilitator even when the run isn’t loaded. The benefit of this is that many runs can be displayed simultaneously in the facilitator page with a set of summary variables without having to load all the runs into memory (which takes time and has limits).

If you build the sim with the interface builder, this context file is created automatically.

Otherwise, you can create your own file. The file must have the same name as Vensim with a different extension. If your Vensim file is “model.vmfx”, name the context file “model.ctx2”.

{
    "variables": {
        "Step": {
            "save": true
        },
        "Time": {
            "save": true
        },
        "Profit": {
            "save": true
        },
        "Revenue": {
            "save": true
        }
    }
}