Announcement

Collapse
No announcement yet.

get field from parent

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

  • get field from parent

    Hello,
    how i can get a field value of parentId on meeting ?
    Thanks

    PHP Code:
    this.listenTo(this.model'change:parentId, function () {
    if (this.model.hasChanged('
    parentId'))  {
         console.log(this.model.get('
    parentId->get('number')'));  // <= get field value from parentId on meeting model :)  
    };
    }, this); 

  • #2
    Hello item try console.log(this.model.attributes.parentId)

    Comment


    • #3
      Hello telecast, find solution with ajax request .. but i will try your response. But this work only on inline edit do you know how i can do this on create/edit view ? https://github.com/espocrm/documenta...ustom-views.md my error is certainly these line : define('custom:views/meeting/record/edit', ['views/record/detail'], function (Dep) { and the path. Regards

      Comment


      • #4
        Addressing "this.model.attributes.parentId" from any javascript script which has a reference to a model as "this.model" will give you the "parentId" value of the model.

        I believe that when you are using the condition " if (this.model.hasChanged('parentId')) {" you are specifying that the action takes place AFTER the model has been changed/updated, so if you are editing normally instead of using inline editing, that condition would not be met until after you have clicked "Save".

        I am not 100% sure because I haven't tested that in my application but hopefully will give you some guidance.

        Cheers

        Comment


        • #5
          Thanks you telecast ... you say me the right way
          work inline and on edit but not on create..(i have a hook in beforeSave isNew who take parent and set field)

          I think, this must be a outOfBox feature... so Meeting must have "address" of parentType .. when printPdf

          My error : the path : custom:views/meeting/record/detail and me : custom:views/meeting/detail
          the extend class : ['crm:views/meeting/record/detail']

          I study your extension.. i learn with that .. thanks

          Regards

          PHP Code:
          define('custom:views/meeting/record/detail', ['crm:views/meeting/detail'],  function (Dep) {
              return 
          Dep.extend({
                  
          setup: function () {
                      
          Dep.prototype.setup.call(this);
                      
          this.listenTo(this.model'change:parentId', function () {
                          if (
          this.model.get('parentId') && this.model.get('parentType') =='Patient' && this.model.hasChanged('parentId') ){
                                  
          this.ajaxGetRequest('Patient/' this.model.get('parentId')).then(function (patient) {
                                     
          this.model.set('place'patient['addressStreet'] +' ' patient['addressPostalCode'] + ' ' patient['addressCity'] );
                              }.
          bind(this));
                          }
                      }, 
          this);
                  },
                  
          afterRender: function() {
                      
          Dep.prototype.afterRender.call(this);
                      
          console.log('custom:views/meeting/record/detail' 'AFTER RENDER');
                      
          // Custom code to be invoked right after rendering, when DOM is available.
                     // this.$el.find('label[data-name="myField"]').addClass('hidden');
                  
          },        
              });
          }); 


          Comment


          • #6
            You're welcome item ,

            Originally posted by item View Post
            I think, this must be a outOfBox feature... so Meeting must have "address" of parentType .. when printPdf
            This is because of how the parent-child link is structured in the database.

            While One-To-Many relationships are linked by a "oneId" field in the "Many" table, Parent-To-Children relationships are linked by two fields in the "Children" table one called "parentId" which has the actual id of the parent record and "parentType" which contains the name of the parent entity.

            For example, assume that you have an entity called "ServiceTicket" that can contain many "WorkOrders", the work_orders table will have a field "service_ticket_id" which will contain the id of the ServiceTicket entity.

            Then assume that you also have an entity "MyNote" that you could attach to Service Tickets or to Work Orders or to any other entity. In this case the my_note table would have two fields to link it with an unknown type of parent (Service Ticket, Work Order or ?) parent_id and parent_type so the system will know the id of the "parent" and the type of entity that the parent is.

            Regards

            Comment

            Working...
            X