Announcement

Collapse
No announcement yet.

Check if the relationship panel is populated from Javascript.

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

  • Check if the relationship panel is populated from Javascript.

    How do I check if a relationship panel is populated for an entity from JS to have some front end validations.

    I have an entity A with a relationship of 1:M with another entity B. And I have the relationship panel which shows the B entities that are linked to A under the detail view of entity A. I need a way to check if there are any B entities linked to A, so that I can enable/disable a certain button.

    How do I go about this using Javascript?

    Thank you! Cheers!
    @telecastg

  • #2
    Variant:

    Make not storable field (entityDefs)

    Code:
     "haveWinQuote": {
    "type": "bool",
    "readOnly": true,
    "notStorable": true
    },
    "haveHarmonizationQuote": {
    "type": "bool",
    "readOnly": true,
    "notStorable": true
    },

    and code like this

    PHP Code:
    namespace Espo\Custom\Services;

    use 
    \Espo\ORM\Entity;

    class 
    Opportunity extends \Espo\Modules\Sales\Services\Opportunity
    {

    public function 
    loadAdditionalFields(Entity $entity)
    {
    parent::loadAdditionalFields($entity);

    $winQuote $this->getEntityManager()->getRepository('Quote')->where([
    'opportunityId' => $entity->id,
    'status' => 'Won'
    ])->findOne();

    $entity->set('haveWinQuote', !empty($winQuote));

    $harmonizationQuote $this->getEntityManager()->getRepository('Quote')->where([
    'opportunityId' => $entity->id,
    'status' => 'In Review'
    ])->findOne();

    $entity->set('haveHarmonizationQuote', !empty($harmonizationQuote));

    }



    Comment


    • AgentT
      AgentT commented
      Editing a comment
      This is cool!
      Thanks.

  • #3
    Another way, mark many fields in relation def, and then control accordingly field

    Example: opportunity-city, field cities

    In entity model you have citiesIds, citiesNames
    Attached Files
    Last edited by dimyy; 08-18-2021, 02:20 PM.

    Comment

    Working...
    X