Recent searches
No recent searches
Uncaught TypeError: client.get is not a function
Posted Sep 03, 2024
In my application, ZAFClient.init() only works in the index, when I go to another page, this error occurs ("Uncaught TypeError: client.get is not a function"). How to fix this error, and make ZAFClient.init() work on other pages? Not just in my index.
This is my code, this is the page pattern, but it only works in my index.
<script>
$(document).ready(function () {
const client = ZAFClient.init();
client.get(['ticket.id', 'ticket.organization.externalId', 'ticket.status']).then(function (data) {
var ticketstatus = data['ticket.status'];
var idcli = data["ticket.organization.externalId"]
var ticket_id = data['ticket.id']
})
});
</script>
0
2 comments
Erica Girges
Hi Adriano,
It could be that this isn't working in your other pages because the apps environment is a single page app framework. So even though the user has navigated to another page the only time that the DOM is loaded is when the app is first loaded. Therefore, document.ready will only run once and with the client variable being stored in that function your other pages can't access it.
I typically recommend using plain javascript to do this rather than jquery. That way you can just import and call the function when needed.
However, if you prefer jquery, I would suggest using a different event to execute the function instead of document.ready maybe with .addEventListener for the load of a page specific element.
Hope this helps!
1
Adriano Dutra
Hi Erica,
Thanks for the answer, I will implement your suggestion. If it doesn't work, I'll come back here with a new question.
Thank for your attention!
0