Refetch new data from ticket when click Next Ticket button

Hi everyone,

I developed a custom app and I’m using Data Method to get data from ticket and displayed the data in the app.

What I am facing now is when I clicked the Next button (as shown in the picture) to move to the next ticket, my app did not re-fetch/get new data from the next ticket but my app just displayed data from previous ticket.

Supposedly when Next button clicked, my app will loading and re-fetch new data from the next ticket.

Can someone help me what to add in my code to re-fetch new data from ticket when clicked the Next button?

Thanks

Hi @luke,
Welcome to the community!

I had checked with my local environment, and I didn’t see any issues with this, data-api is fetching the correct details when there is a navigation, possible can you please share the code snippet your are trying, we can help you further.

Thanks

1 Like

Hi @Santhosh

This is my code to fetch email from ticket.

function setUserEmail() {
      app.initialized().then(client => {
        client.data.get('contact')
          .then(function (data) {
            var email = data.contact.email
            startAppRender(email)
          })
          .catch(function (error) {
            console.error('Unable to fetch current contact', error);
          });
        })
    }

function isDocumentReady() {
    if (document.readyState != 'loading') {
      document.addEventListener('DOMContentLoaded', startAppRender);
      console.info('Browser waiting until DOM loads...');
    } else {
      document.addEventListener('DOMContentLoaded', setUserEmail);
    }
  }

Is it because I put the function (get email from ticket) in else {} ?

1 Like

Nope it is not because of that, already tested on local

@luke,
Can you try like this?

if (document.readyState === 'complete') { 
document.addEventListener('DOMContentLoaded', setUserEmail);
}

this will call every time once the DOM render is completed,

Hope it helps :slight_smile:

Hey @luke

I think you should listen to “app.activated” event. As pointed out in the documentation:

To enable the app to refresh itself at the right time, the ticket page triggers an app.activated() event. Apps in the ticket_sidebar location are initially in a minimized state. When the agent expands the app for the first time on the page, the app receives the app.activated() event. If the agent navigates to another ticket and then expands the app (for the first time on that page), the app.activated() event is triggered again.

When the ticket page is loaded for the first time, the app.js file registers for the app.initialized() event. In the callback, it receives a client object and registers for the app.activated() event. The core logic of the app, which is to retrieve the ticket requester’s name and append it to a string, is contained in this callback.

https://developers.freshdesk.com/v2/docs/your-first-app/

I tested it here and clicking in “Next” button, always fire this event.

5 Likes

Great it’s working, millions thanks!

2 Likes