When working in Debug mode, you have also noticed (and this is not a surprise) that some interesting objects and functions are available that do not show up when the project is deployed. This is not a surprise really. But in our case, we would like to have access to our array of data for our (perhaps twisted and even unprecedented) purposes. So where do we go from here? The answer, as always, turns out to be relatively simple.
The interview object contains a reference to the same array in the form of interview._session.config.data.instances. Note that the number one assumes that you have only two entities, Global and something else. You will have to inspect your code and find out which node you are interested in if you have more. It looks like this in my case.
Once you have that reference, you can do two things easily.
- You can figure out the length of the array and use it in your for…each loop
- You can select one of the child array called attributes and dig up the information you need to display
So in this new, non-Debug version of the code, you would end up with the following changes compared to the previous post.
- In the early part of the script, get a reference to the part of the interview object you need
- Use it in a similar way to previously to get the different attribute values you want to display
This code will run even if you are not using the debugger and you have deployed the project to an Interview URL.
But there is another caveat. The exact index (location) of your entity in the array of entities will change as you compile and deploy your project. So we need a mechanism to make sure we have selected the correct entity and instances. What today is index 3 might be index 2 tomorrow. Since the entity you are looking for has a unique public name, you might use that to find it. Something like this (based on code taken from stackoverflow.com).
Working through the different nodes until you find the right one, based on the unique name.