Custom button visibility control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • override
    Junior Member
    • Mar 2018
    • 21

    #1

    Custom button visibility control

    I have created a custom button
    Code:
    custom/Espo/Custom/Resources/metadata/clientDefs/Email.json
    and a handler class
    Code:
    client/custom/src/createProductionHandler.js
    Everything works fine except for a visibility part where I have to check if Parent has some field set or not.
    Code:
    isCreateProductionVisible() {
    
    if ((this.view.model.get('parentType') == 'Order') && this.view.model.get('parentId'))
    {
    Espo.Ajax.getRequest('Order/' + this.view.model.get('parentId')).then(order => {
    if (order.productionId)
    {
    console.log('Has Production');
    return false;
    }
    else
    {
    console.log('Doesnt have Production');
    return true;
    }
    
    });
    
    }
    console.log('Leaving visibility check');
    return !((this.view.model.get('parentType') == 'Production') && this.view.model.get('parentId'));
    
    }
    The problem is that
    Code:
    isCreateProductionVisible
    returns before
    Code:
    Espo.Ajax.getRequest
    completes.
  • yuri
    EspoCRM product developer
    • Mar 2014
    • 9617

    #2
    Try calling this.view.model.trigger('sync'), this will mimic the model being saved or fetched and will force visibility update.

    Comment

    • override
      Junior Member
      • Mar 2018
      • 21

      #3
      Ok, that's it. Thanks

      Comment

      Working...