I created a lightning component to close the console tab and i want to do this whenever its child objects' field (status__c) is changed to "Completed". I am using setInterval to check the field value constantly but the poller method seems to be running even after the flexipage where this component is embedded is closed.
AccComponent.cmp
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,lightning:isUrlAddressable" access="global" controller="AccountViewController" >
<!-- Id of the Account the page hosting this component is showing -->
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="Interactions" type="vlocity_ins__CustomerInteraction__c" />
<lightning:workspaceAPI aura:id="workspace" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
</aura:component>
AccComponentController.js
({
doInit : function(component, event, helper) {
console.log("Tab Focused");
helper.pollApex(component, event, helper);
},
})
AccComponentHelper.js
({
getJsonFromUrl : function () {
var query = location.search.substr(1);
var result = {};
query.split("&").forEach(function(part) {
var item = part.split("=");
result[item[0]] = decodeURIComponent(item[1]);
});
return result;
},
pollApex : function(component, event, helper) {
//execute callApexMethod() again after 5 sec each
window.setInterval(
$A.getCallback(function() {
helper.callApexMethod(component,helper)
}), 5000
);
},
callApexMethod : function (component,helper){
console.log("Record Id in Aura: "+component.get("v.recordId"));
console.log("Interaction Id in Aura -- > interId :: "+helper.getJsonFromUrl().vlocity_ins__interactionId);
var recId = component.get('v.recordId');
var interId = helper.getJsonFromUrl().vlocity_ins__interactionId;
if(recId != null && interId != null ){
console.log("::: TRUE HERE :::")
}else{
console.log("::: FALSE HERE :::")
}
}
})
I am seeing "::: TRUE HERE :::" in console log when I am on flexipage for account and also I am seeing "::: FALSE HERE :::" when I am on Home page after closing the account tab.
Can anyone explain me reason for this behavior and how can I make this component to be invoked only while on flexipage?