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-02-2022 06:33 AM
You can't do that, you are trying to fetch the value that is within the function(local) scope, you got to update the field inside the callback function only
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 11:28 PM
But the variable is not in local scope na I'm justupdating the value?I hv further more code so I need the value outside

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 12:35 AM
But since you are accessing the value from outside the callback function, it will still refer to global value that has been set, why can't you include rest of your code inside callback function only?
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 11:37 PM
Hi,
Why are you not writing as
var name='abc';
if(user!=' '){
var x = g_form.getReference('user', callFunction);
}
function callFunction(x){
var managerName=x.manager;
name=name+"_" + managerName;
}
alert(name);
Regards,
Sumanth