Ticket ID not being pass through other model or other page

Hello everyone,

I would like to ask for help about my issue.

I am developing custom app inside the ticket interface.
I got challenge when displaying ticket id after user view any ticket that are available, for example ticket id = 208, so when I open my app it should capture or automatically load the ticket id. So I test various logic to make it appear, now I am able make it appear only if user click any button for it to trigger. This is on index.html file. (First Layer Form)

Second issue is, my createticket.html file (Second Layer Form). In here I want the ticket Id being automatedly display but still same issue like the index.html file.

I will provide my index code first, if you need my second code, feel free to inform me.

this is code snippets for my index.html

<div class="ticket-id" id="ticket-id-display">
        <p><strong>Freshdesk Ticket ID:</strong> <span id="ticket-id"></span></p>
    </div>

 async function openModal(action) {
            let templatePath = '';
            let title = 'Sample Modal';
            let data = {};

            switch (action) {
                case 'view':
                    templatePath = './views/viewticket.html';
                    break;
                case 'create':
                    templatePath = './views/createticket.html';
                    title = 'Create Ticket';
                    try {
                        const ticket = await client.data.get('ticket');
                        data.ticketId = ticket.ticket.id;
                        console.log('Fetched ticket ID:', data.ticketId);
                        document.getElementById('ticket-id').textContent = data.ticketId;
                    } catch (error) {
                        console.error('Error fetching ticket data:', error);
                    }
                    break;
                case 'update':
                    templatePath = './views/updateticket.html';
                    break;
                case 'sync':
                    templatePath = './views/syncticket.html';
                    break;
                default:
                    console.error('Invalid action:', action);
                    return;
            }

            try {
                client.interface.trigger('showModal', {
                    title: title,
                    template: templatePath,
                    data: data
                }).then(function(data) {
                    console.log('Modal closed successfully:', data);
                }).catch(function(error) {
                    console.error('Error displaying modal:', error);
                });
            } catch (error) {
                console.error('Error triggering modal:', error);
            }
        }

        // Ensure Freshworks client is initialized
        async function initFreshworksClient() {
            try {
                await client.init();
                console.log('Freshworks client initialized successfully');
                // Fetch and display ticket ID on page load
                const ticket = await client.data.get('ticket');
                document.getElementById('ticket-id').textContent = ticket.ticket.id;
            } catch (error) {
                console.error('Error initializing Freshworks client:', error);
            }
        }

       
        fetchData();

      
        document.addEventListener('DOMContentLoaded', function() {
            console.log('DOM fully loaded and parsed');
            initFreshworksClient();
        });

AfterClickButton

CreateTicket

TicketID

Hi @im_chung,

Welcome to the Freshworks developer community! :tada:

Refer to the App LifeCycle methods; It will have the instructions on when the app will be initiated and activated depending on the app placeholder used.

If the app is rendered in the ticket_sidebar app location, the app will be initiated as soon the ticket details page is opened. The app will be activated when the app is opened. So, the app will get the ticket id and display it as soon as the app is opened with onAppActivated life-cycle method.

If the ticket ID is not displayed in the index.html, can you debug with more logs to see what’s happening and what is not being working as expected?

1 Like

hai @Raviraj ,

I have succeed to code it through the index and modal page, by using the lifecycle methods, Thanks a lot !

1 Like

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.