0

Is there any way to assign value to global variable in salesforce helper javascript?

Helper

({
    resetTime: 30000,
    refreshNotif: function(component, helper) {

            window.setInterval(
                $A.getCallback(function() {
                    console.log('test 1');
                }),
                helper.resetTime

            );
        },
 updateRead: function(component, helper) {
        helper.resetTime = 50000;

}
})

my question is, when page loads the refreshNotif function is getting called and the reset time value should be 30000. but when updateRead function is called how can i assign the value 50000 to resetTime global variable so that helper.resetTime in the refreshNotif function should also get updated to 50000.

is my approach above is correct?

Right now the value is set to 30000 even when the second function getting called

1 Answer 1

0

Use Aura attribute to store the resetTime value, you can easily access that from the helper.

<aura:attribute name="resetTime" type="Integer" default="30000"/>

set that from helper

updateRead: function(component, helper) {
    component.set("v.resetTime", 50000);
}

get it like this,

let time = component.get("v.resetTime");
4
  • 1
    it worked. thanks
    – Arzad
    Commented Mar 19, 2020 at 15:35
  • @Arzad Most welcome! Commented Mar 19, 2020 at 15:44
  • is there a way to declare global variable without initializing a value in JS controller in salesforce? Ex: resetTime: , refreshNotif: function(component, helper) { // } assigning values to global variable dynamically?
    – Arzad
    Commented Mar 20, 2020 at 5:00
  • @Arzad you can set it to undefined, but I doubt if you can change that value later. In my personal opinion it is always better to use aura:attribute. Commented Mar 20, 2020 at 5:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .