define('custom:views/dashlets/lead-switch', ['views/dashlets/abstract/base'], function (Dep) { return Dep.extend({ name: 'lead-switch', template: 'custom:dashlets/lead-switch', setup: function() { Dep.prototype.setup.call(this); this.url = ''; // Initialize with empty this.fetchUserId(); }, fetchUserId: function() { Espo.Ajax .getRequest('App/user') .then(response => { //console.log("Full Response:", response); if (response && response.user && response.user.id) { this.url = "https://app.abs.com/lead-switch?id=" + response.user.id; //console.log("URL:", this.url); this.reRender(); // Re-render the component } else { console.error("User ID not found in response"); } }) .catch(error => { console.error("Error fetching user data:", error); }); }, afterRender: function () { var $iframe = this.$el.find('iframe'); var url = this.getOption('url'); if (url) { $iframe.attr('src', url); } this.$el.addClass('no-padding'); this.$el.css('overflow', 'hidden'); var height = this.$el.height(); $iframe.css('height', height); $iframe.css('width', '100%'); }, data: function() { return { url: this.url }; } }); });