call time difference not showing after status change or after save/update

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • elbowprogrammer
    Member
    • Jan 2016
    • 58

    call time difference not showing after status change or after save/update

    I created field in Call entity named time_call. I'm trying the set the date completed and time_call when the status has been changed to "Held". Not sure how to do it on the server side, so I tried to do it on the client side (client/modules/crm/src/views/call/detail.js) in the setup function. The fields are changing when the field is held, but it is not shown when I change the status or even after I update/save it. I would have to update/save, get out of the Call item, then go back in it just to see the fields changed. My code is below. This issue to resolved is on a time clock. I would very appreciate a quick response. Also is there a isfieldchanged on the client side, or do I just use model.hasChange([attribute])?
    Code:
                 if(this.getAcl().checkModel(this.model,'edit')){
              //      if(['Held'].indexOf(this.model.get('status')) != -1){
                    if(this.model.get('status') == "Held"){
                        //  var diff = (moment(this.model.get('dateCompleted')).unix() - moment(this.model.get('dateStart')).unix()) / 3600;
                        var dateEnd = moment(this.model.get('dateEnd')).unix();
                        var dateStart = moment(this.model.get('dateStart')).unix();
                        var diff = Math.abs(dateEnd) - Math.abs(dateStart);
                        var time_call = Math.ceil((Math.floor(diff) / 3600) * 100) / 100;
       
      
                        this.model.save({
                            'dateCompleted': this.getDateTime().getNow(),
                            'time_call': time_call
                        });
                    }
                    else{
                        this.model.save({
                            'dateCompleted':null,
                            'time_call':null
                        });
                    }
                }
    Last edited by elbowprogrammer; 05-03-2016, 04:43 PM.
  • jcortes0309
    Member
    • Mar 2016
    • 68

    #2
    Check out how it's done in the Tasks code

    Code:
        protected function beforeSave(Entity $entity, array $options = array())
        {
            parent::beforeSave($entity, $options);
            if ($entity->isFieldChanged('status')) {
                if ($entity->get('status') == 'Completed') {
                    $entity->set('dateCompleted', date('Y-m-d H:i:s'));
                } else {
                    $entity->set('dateCompleted', null);
                }
            }
    This can be found in the \application\Espo\Modules\Crm\Repositories\Task.ph p file. You should be able to do something similar when the status is Held.

    Comment

    • elbowprogrammer
      Member
      • Jan 2016
      • 58

      #3
      Manage to get it to work. I knew of the code for Task entity, but I was hoping to do it on the client slide instead. I manage to get it to work with the Task code for the datecompleted and the time diff. For future reference, is it possible to do it on the client side?

      Comment

      Working...