Hi team,
We have a custom FD app built in house to assist our needs, the application seems to be glitching, the problem we are facing is that the app.initialized() is not getting called and the client is not available for us to fetch data from.
document.addEventListener("DOMContentLoaded", () => init());
async function init() {
app
.initialized()
.then(function (_client) {
window.client = _client;
client.events.on("app.activated", showUI);
})
.catch(function (error) {
showError("Unable to get FD client");
console.error(error);
});
}
Below is the head section of index.html
<head>
<title>Support HQ</title>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://static.freshdev.io/fdk/2.0/assets/fresh_client.js"></script>
<script async src="{{{appclient}}}"></script>
<link rel="stylesheet" type="text/css" href="styles/style.css" />
<script async type="module" src="https://unpkg.com/@freshworks/crayons@3/dist/crayons/crayons.esm.js"></script>
<script async nomodule src="https://unpkg.com/@freshworks/crayons@3/dist/crayons/crayons.js"></script>
<script src="scripts/app.js"></script>
</head>
Hi @Suyash_Sonawane ,
Welcome to the community
Please refer to the sample apps repo below, where you can find different applications with different placeholders. And also check this repo too
Hope that helps!
Let me know otherwise
Thank you
We are following the similar approach as
document.onreadystatechange = function () {
if (document.readyState === 'interactive') renderApp();
};
async function renderApp() {
let _client = await app.initialized();
window['client'] = _client;
client.events.on('app.activated', renderSidebar);
return;
}
function renderSidebar() {
const dataMethBtn = document.querySelector('.btn-ticket-details');
const space = document.querySelector('.space');
dataMethBtn.addEventListener('fwClick', function getTktDetails() {
/** ~ playground start of ticket details page ~ */
But the promise doesn’t get resolved
Hi @Suyash_Sonawane ,
Greetings!
Could you try with the Promise(refer to the code below).
const onAppInitializedCallback = (_client) => {
window.client = _client
}
app.initialized()
.then(onAppInitializedCallback)
.catch(() => {
console.log("oops!")
})
Because I have experienced issues with await in FS in the past. Getting the client in a callback fixed the issue for me.
Let’s hope the same
Thank you.
system
(system)
Closed
June 4, 2024, 4:33am
5
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.