Var undefined.... (but is available one line above)


hi gurus,

Sorry, this feels so dumb… But do you know why my var senseConfig.slideGeneratorAppId is undefined?


Template.ppt_integration.onCreated(function() {    
    console.log('############# Template.ppt_integration.onRendered');
    console.log('senseConfig', senseConfig);
    console.log('senseConfig.slideGeneratorAppId', senseConfig.slideGeneratorAppId);
    config = {
        schema: qixschema,
        appId: senseConfig.slideGeneratorAppId, //Cookies.get('slideGeneratorAppId'),
        session: { //
            prefix: Meteor.settings.public.slideGenerator.virtualProxy,
            port: senseConfig.port,
            unsecure: true

thanks a lot… this is so weird… (please note that my config object has fixed values from my settings.json file, that works fine. If the client starts I get the APPID from another server and add that to my config file, this works fine on another page in my application when I do this in onCreated)…


The only debug advice I have is that if you are using some kind of reactive value, then I can confirm that this kind of weirdness can happen.

I’ve seen instances where a reactive object is updated, and the console will display the updated value, even though you’d expect the kind of synchronous behavior via console logs like you are trying here.


mmm, it is a normal var (not reactive), I know solved it by using a cookie, would it help if I make it a reactive var?

Please also not that I only got this behavior after I put the same app in an iframe…

  • parent no issue
  • iframe has this issue…
//This is the config that we need to make available on the client (the webpage)
if (Meteor.isClient) {
    var _senseConfig = {
        "QIXSchema": _QIXSchema,
        //ssbi and slide generator app id are set automatically on main.js (client side, via a call to the server)
        // config.SSBIAppId = 
        // config.slideGeneratorAppId = 

client main.js

Meteor.startup(function() {'getAppIDs', function(error, IDs) {
            senseConfig.SSBIAppId = IDs.SSBI;
            senseConfig.slideGeneratorAppId = IDs.slideGenerator;
            Cookies.set('slideGeneratorAppId', IDs.slideGenerator);


The iframe will not have any data from the parent, so any data you want in it has to be initialized inside the iframe


Thanks, that is what I saw with for example Session vars, cookies work fine then.

So what could be happening is that I see the console.log of both the parent as well as the IFRAMED window. note: they both contain the exact same meteor app. (but show a different route)

So how would you explain the contents of the var then? first it exists, row below not anymore…


What @vigorwebsolutions is saying is true for any object variable, not just a reactive variable. The console.log is showing you the live object, not the state of the object at the time it was logged. To demonstrate, try this in your javascript console:

test.b        // undefined

then expand the test object in the console and you will see it contains b=12 even though it was logged before test.b existed!

Try replacing your code with

console.log('senseConfig', JSON.stringify(senseConfig));

and you will see that slideGeneratorAppId doesn’t exist at that point in the code.

You said that the APPID is fetched from another server and so the response will probably not be available by the time the onCreated function is called. Whatever you are doing with the senseConfig.slideGeneratorAppId variable, you need to do it within the callback of'getAppIDs'... so you can be sure it’s ready.

Alternatively, make sure senseConfig is reactive then put your onCreated code into an autorun which checks for the existence of senseConfig.slideGeneratorAppId before doing anything with it, then stops the autorun.