Let's say in my custom aura component, There's a spinner that indicates that we're still processing your record. What I want to happen is if that aura component is still open in a tab and a record that is related to that page is updated. I want to automatically reload the page. What I've tried so far are the following
1.) setInterval function
- in my doInit
method i have a setInterval function
that calls a method in the controller class wherein I try to query the record to check if it was updated or not. Which doesn't work because it's not returning any data maybe because of the combination of setInveral
and callbacks
.
Controller
setInterval(function(){
helper.CheckIfRecordIsUpdated(component,event,helper);
},
5000);
Helper
function checkIfRecordIsUpdated(component,event,helper){
var recordId = component.get("v.recordId");
var getNewStatus= component.get("c.getNewStatus");
getNewStatus.params({"recordId" : recordId})
getNewStatus.setCallback(this,function(response){
//DOES NOT ENTER HERE
});
$A.enqueueAction(getNewStatus);
}
2.) force:recordData
- The issue with force:recordData
is it will only detect the change on the record if i refresh the page.
<force:recordData
recordId="{!v.recordId}"
targetFields="recordField"
recordUpdated="{!c.recordUpdate}" />
Is there anyway for me to achieve this? Is this even possible in aura component?