sugarcrm

SugarCRM: How to get the id of a dashlet (not dashboard) in the dashlet controller .js file?


I am accessing this.model.attributes and it returns

{
  "id": "suihio-32b3-432jk4-43n" // This is the Dashboard id
  "dashboard_name": "Test Dashboard",
  "metadata": {
    "dashlets": [
      {"id": "23434-34234f-34ffkke-jnsd", "name": "Test dashlet 1", ...},
      {"id": "bsdu7svs-v34343f4w-4f34f4-4f43", "name": "Test dashlet 2", ...},
      ...
    ]
  }
}

I am unable to get the dashlet id in the dashlet controller .js file. Always, I have to filter using the name of the dashlet within the metadata->dashlets array, so facing issue when multiple dashlets are there with same name.

I want to know how I can get the particular dashlet id from the controller .js file.

Thanks in advance.


Solution

  • After searching in millions of places, finally I found a solution. The is is not there in any property of the this object. But it is placed in the dashlet container layout div as a data attribute.

    We need to use

    var dashletId = this.layout.el.dataset.gsId;
    

    to get the id. But if we query it directly inside the controller, it will provide us undefined as the html is not rendered till now. We have to add a timeout before querying the same as below.

    setTimeout(_.bind(function () {
        var dashletId = this.layout.el.dataset.gsId;
        this.render();
    }, this), 0);