Announcement

Collapse
No announcement yet.

Get all record related on click from custom button and convert to json

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get all record related on click from custom button and convert to json

    I was able to press the button, and later publish it as I did.

    Now I have defined an action that lists all the relationships with the distribution list and I would like to capture the list of all the associated records.

    Code:
      
    
    
    actionListaRecordRelation: function () {
    
        var scope = this.scope;
    
        this.wait(true);
        this._helper.layoutManager.get(this.model.name, 'relationships', function (layout) {
                var panelList = layout;
                panelList.forEach(function (item) {
    
    [COLOR=#FF0000]// here I would like to capture all the linked records and turn them into JSON arrays[/COLOR]
    
    
                }.bind(this));
    
                this.wait(false);
        }.bind(this));
    }
    Do you have any idea how I can do it? thank you
    Last edited by enricorossa; 09-06-2019, 01:20 PM.

  • #2
    Code:
    var relationshipsData = this.relationshipsData = {};
    var promiseList = [];
    var id = this.model.id;
    
    panelList.forEach(function (item) {
        var promise = new Promise(
            function (resolve) {
                Espo.Ajax.getRequest(scope + '/' + id + '/' + item)
                .then(
                    function (response) {
                        relationshipsData[item] = response;
                        resolve();
                    }
                );
            }
        );
        promiseList.push(promise);
    });
    
    
    this.wait(
        Promise.all(promiseList)
    );
    Last edited by yuri; 09-06-2019, 07:11 PM.

    Comment


    • #3
      If it's inside the action method, you don't need to use 'wait'. Wait is needed only inside setup method to hold off rendering before all needed data is ready (loaded).

      You can change the last 3 lines of my code to

      Code:
      Promise.all(promiseList).then(
          function () {
              // do something  
          }
      );

      Comment


      • #4
        thanks really, I got just what I wanted I missed the step Espo.Ajax.getRequest,
        ut unfortunately when I retrieve the email address field it only returns an email address to me while some accounts have 2 or 3 addresses loaded, you can recover them all ?
        Thanks again

        Comment


        • #5
          You will need to make a request for each record in the list to fetch all email addresses

          Espo.Ajax.getRequest(entityTypeOfRelated)

          Comment

          Working...
          X