The CreatorCon Call for Content is officially open! Get started here.

how to update variable inside callback function

Akki1
Tera Contributor

HI, I have defined variable outside and i want to update the value inside callback . How can i do it.

I have tried to explain my scenario using an example.

var name='abc';

if(user!=' '){

var x = g_form.getReference('user', callFunction);

function callFunction(x){

var managerName=x.manager;

name=name+"_" + managerName;

}

}

alert(name);     // I'm not getting the updated name it still shows abc 

//The goal I want to achieve is the variable to update the value and use it outside callFunction

 

22 REPLIES 22

You can either write the whole code inside the callback function or you can use setTimeout, which will delay a bit until data is received.


Please mark my answer as correct if this solves your issues!

If it helped you in any way then please mark helpful!

 

Thanks and regards,

Kartik

pratapdalai
Tera Contributor

The variable scope is causing the issue .One more thing I observed that 

 

name=name+"_" + managerName;  // Should not be like name=x.name+"_" + managerName;

no the variable name is defined outside the function