I am trying to get some details for the current logged-in user via JavaScript so i can make some interface changes but i can't find a way to get the id
how to get details for current logged in user via javascript?
Collapse
X
-
If you are extending a view then you can do something as below
PHP Code:this.getUser().get('teamsNames') // get the user's teams names
this.getUser().id // get current logged in user's id
const userModel = this.getUser() // this the current logged in model instance
-
no i am just doing vanilla JS. Do you know any good examples of extending a view? It's been 15 years since I worked with vanilla JSComment
-
can you share what your trying to do with your code?
or creating a view see below
Comment
-
o i see so you can customise one entity's view, interesting, and yeah, i can see the use of itcan you share what your trying to do with your code?
or creating a view see below
https://docs.espocrm.com/development/custom-views/
but what i was doing was a compact view for multiple entities controlled by a user-defined toggle
at the time of posting, i think the user api endpoint on my host was stuck and was only showing the first user. After rebooting Docker, i found that it would serve the current logged-in user so i was able to use those details to turn on and off a style sheet via js
here is how i did it
<the call>
<the lib>Code:document.addEventListener('DOMContentLoaded', () => { Espo.loader.require('hiden:User', async function (User) { const myInstance = new User(); const isCompact = await myInstance.checkIsCompact(); if (isCompact) { loadCSS('client/custom/css/compact.css'); } }); });
Code:define('hiden:User', [], function () { class User { async checkIsCompact() { const response = await fetch('api/v1/App/user'); const data = await response.json(); return data.user.cCompactView; } } return User; }); function loadCSS(url) { const link = document.createElement('link'); link.rel = 'stylesheet'; link.href = url; document.head.appendChild(link); }Comment

Comment