Not able to retrieve treatment value out of the function, neither being able to print the value

Comments

6 comments

  • Samantha Pereira

    Edit: I need to write code outside this function and so need the value of the treatment to be returned and used else where, I don't want to write any code within this if else block. Any suggestions?

    0
    Comment actions Permalink
  • Bilal Al-Shahwany

    Hi Samantha,

    Regarding not seeing the treatment, your code check for client.ready() promise, which means you will see the treatment only when the promise resolve, did you set the startup.readyTimeout parameter? If yes, what os the value? We recommend to set it to 5 (seconds).

    I would enable debug logging by adding "debug: true" config parameter and check the browser console for the SDK log output. 

    Regarding accessing the treatment value outside of the block, you need to declare the treatment variable as global outside the block, then it will be accessible from anywhere:

    Thanks

    Bilal

     

    0
    Comment actions Permalink
  • Samantha Pereira

    Thanks Bilal Al-Shahwany

    This is what I added for startup.readyTimeout as per your suggestions

    if (environment.splitIOLocal !== 'on') {
    constfactory:SplitIO.ISDK=SplitFactory({
    core: {
    authorizationKey:getSplitIOAuthToken().auth_key,
    },
    startup: {
    readyTimeout:5
    },
    });
    this.client=factory.client();

    this.client.on(this.client.Event.SDK_READY, () => {
    });
    }
    0
    Comment actions Permalink
  • Samantha Pereira

    debug: true doesn't seem to work since this is not on the browser.

    0
    Comment actions Permalink
  • Samantha Pereira

    Also, it's not about declaring the variable global, it's unable to hold treatment value outside client.ready()

    It gets the value as null outside the block.

    0
    Comment actions Permalink
  • Bilal Al-Shahwany

    Hi Samantha, you are logging the treatment value right after declaring the factory, which will always be null, you need to log it within the SDK_READY block.

    this.client.on(this.client.Event.SDK_READY, () => {
    treatment = this.client.getTreatment(key, splitName, attributes);
    console.log(treatment);
    });
     
     
    Thanks
    Bilal
    0
    Comment actions Permalink

Please sign in to leave a comment.