Recent searches
No recent searches
Client.get() and client.context() returning data for all currently open tickets
Posted Jan 20, 2022
Hi,
I have this piece of code in my ticket sidebar app (this is a simplified example):
client.context().then(context => {
console.log("CONTEXT", context);
this.context = context;
});
client.get("ticket").then(ticket => {
console.log("TICKETDATA", "ID=" + ticket.ticket.id, "SUBJECT=" + ticket.ticket.subject);
this.ticketData = ticket;
})
However, when my app loads/refreshes, this results in the ticket data and context being loaded for all open tickets (open ticket tabs), not just the ticket tab in focus. Is this intended behaviour? I have used the apps framework for some years and never noticed this before. A screenshot from our sandbox:
If it is intended, how do I identify which ticket is in focus, so I can grab the ticket data with client.get("ticket") (or sub-properties, e.g. client.get("ticket.organization.organizationFields")) for just that ticket? In the example above, for #1635. I would have assumed that at least only one context (which includes a ticket ID) was fetched, but I also get all three of those, as can be seen.
Thanks for any input.
Kind regards,
Chris
1
4 comments
Eric Nelson
Hey Chris,
Each ticket that has an open tab has its own isolated instance of the app running (You can see this by looking at the instanceGuid in your screenshot). When you do a full reload of the browser window it reloads all downstream objects, this includes these different instances of the app. As each instance is isolated any actions that you take will only affect that instance / associated ticket.
So using your example if you were to wanting to grab the ticket's organization fields and present them in the app. The only ones that would show are the ones for the ticket in focus.
Hope this helps clarify things
0
Christoffer Jon Sinnbeck
Eric Nelson Thanks Eric. Will look into this.
What confused me was that this also happens if I just refresh the app-pane on one of the open tickets by clicking the "reload apps" icon (no need to do a full browser reload). So, when the apps are reloaded on one ticket, the client.get call is fired for all three app panes (on the three open tickets) - I am pretty sure this is what I am seeing.
Kind regards,
Christoffer
4
Molly Katolas
Heyya - we're seeing this behavior as well. Was there ever any resolution to identify which ticket is in focus?
0
Tipene Hughes
Wrapping the function(s) in a
client.on('app.activated', ()=>{})
method should prevent this from happening. Here's a link to the docs which explains the app.activated event in a bit more detail:https://developer.zendesk.com/api-reference/apps/apps-core-api/core_api/#appactivated
I hope this helps! Feel free to reach out with any questions.
Tipene
0