Basic App - outputting contact details

Hi, Newbie here trying to develop a basic custom app in freshsales that will pass some contact details to a webpage. I’ve followed the guides, created an app with FDK and tried some of the how to’s but without any luck.

I have a module working in the contacts menu, the index.html page loads and i can call the app.js script, however i can’t seem to get the data context and output anything to do with the current contact record.

here’s a breakdown of my simple code - hoping someone can help explain where it’s going wrong.

Manifest

{
“platform-version”: “3.0”,
“modules”: {
“common”: {
“requests”:{

  }
},
"contact": {
  "location": {
    "contact_entity_menu": {
      "url": "index.html",
      "icon": "styles/images/icon.svg"
    }
  }
}

},
“engines”: {
“node”: “18.20.1”,
“fdk”: “9.7.1”

}
}

Index.html

Contact Info

Contact Info

Loading contact...
<script src="scripts/app.js">

// “app” is provided by “fresh_client.js”
app.initialized().then( async function (client)
{
let appClient = client;

document.getElementById(“output”).innerText = appClient

}

</script>

App.js

async function getCurrentEntityInfo() {
try {
const data = await client.data.get(“currentEntityInfo”);
// success output for contact
// data: { “currentEntityInfo”: { “currentEntityId”: 12, “currentEntityType”: “contact”}}
document.getElementById(“output”).innerText = data
console.log(data);
} catch (error) {
// failure operation
console.error(error);
document.getElementById(“output”).innerText = error
}
}

getCurrentEntityInfo();

nevermind, i worked it out by going back to the fdk template which had the right hooks in my app.js

here is a corrected app.js that grabs the contact entity correctly.

let client;

init();

async function init() {

client = await app.initialized();

client.events.on(‘app.activated’, renderText);

}

async function renderText() {

const textElement = document.getElementById(‘apptext’);

const iframeElement = document.getElementById(‘contactIframe’);

const contactData = await client.data.get(“currentEntityInfo”);

const contactId = contactData.currentEntityInfo.currentEntityId;

// Display the contact ID

textElement.innerHTML = `Contact ID: ${contactId}`;

}