how to update variable inside callback function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 06:28 AM
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
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 09:36 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 01:55 AM
The variable scope is causing the issue .One more thing I observed that
name=name+"_" + managerName; // Should not be like name=x.name+"_" + managerName;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 03:01 AM
no the variable name is defined outside the function