My custom app is not getting updated currentEntityInfo when contact is changed to a new contact. My app is loaded on contacts pages in freshsales crm. The app.activated is triggered and I call client.data.get inside the app.activated event handler, but the contact ID I get back is from the contact that was loaded initially. Regardless of how many times I change the contact, the original contact id is returned.
Here are the steps:
- Load a contact
- Select my custom app in left nav
- View console log and see the client id for the correct client is printed
- Search for a new contact in the searchbox at top of page
- Pick a different contact from the search results and wait for page to load
- Select my custom app in left nav
- Observe the client id from the previous contact is printed
Below is the code:
document.onreadystatechange = function () {
if (document.readyState === 'interactive'){
app.initialized().then(function (_client) {
log.setLevel('trace')
window.client = _client
client.events.on('app.activated', function(){
log.info('SAFR App Activated.')
// The Data Method is used after the app is activated
client.data.get('currentEntityInfo').then(function (data) {
var contact_id=data.currentEntityInfo.currentEntityId
log.info('Got Contact ID', contact_id)
window.contact_id=contact_id
})
})
})
}
}
Each time I load a contact, I see the log “SAFR App Activated” followed by a contact Id. But every time the contact Id is for the first contact that was loaded.
Even if I don’t load my custom app for the first contact, if I then load 2nd contact and open the custom app for that contact, the contact_id printed is for the very first contact that was loaded.
So in this case the flow is like this:
- Load contact 1
- Use search at top and load contact 2
- use Search and top and load contact 3
- Open my custom app → Observe contact Id for contact 1 is printed in log.
I’ve followed guidance on Control the context within the app with App Lifecycle Methods to the best I can see.
Can someone help please explain what I’m doing wrong to not get refreshed contact id?