AnsweredAssumed Answered

Sugar 7 Standard callback() functionality is   not working  in validations

Question asked by KD KD on Oct 4, 2014
Latest reply on Sep 21, 2015 by Caim Astraea
Hello All,
I was trying to run Validations on Note Module, and try to show pop up message. Now it shows the error message but unfortunately it save the note as well.Actually it should not allow to save note if validation criteria met.

Below is code that I was trying ,I put number of hours to build it now some issue is with, i think with callback or "this" reference and causing the Note to save even "validation" is true.

So,please tell me what is wrong with my code or is it Sugar 7 issue/bug?
I have tried (TRY 1,2 and 3 as shown in code below ) using callback()  at three places , but does not work.

Thanks 

==================
   initialize: function (options){      this._super('initialize', [options]);
    
        this.model.addValidationTask('Note_Validations', _.bind(this._note_Validations, this));
   
           }, 
    _note_Validations: function(fields, errors, callback) {
       
        // Note Status Validations
       // The functionality will run when User found in Team AND checkNoteStatus will return True

         var  error_status =false;
   console.log("IN CHECK NOTE STATUS VALIDATION FUNCTION XXXX");
      var caseid_team;
   var case_number_team;
   var case_status_team;
   var case_type_team;
   var note_status;
   var noteCaseTeam;
   var parentthis_Team = this;
   //Get and Set "Note Status' as "Parent Case" Status
  caseid_team = this.model.get('parent_id');
  console.log("case ID IN TEAM CHECK is 123"+this.model.get('parent_id'));
  console.log("case ID TEAM CHECK is 446"+caseid_team);
  noteCaseTeam = App.data.createBean('Cases',{id:caseid_team});//Return the object of Team
     noteCaseTeam.fetch({
   success:function() 
   {
                // flag = true;
  case_number_team  = noteCaseTeam.get('name');
     case_status_team  = noteCaseTeam.get('status');
     case_type_team = noteCaseTeam.get('type');
     console.log("case Number is INSIDE "+case_number_team);
     console.log("case Status is INSDIE"+case_status_team);
     console.log("case Type is INSDIE"+case_type_team);
       console.log("This here is123 "+parentthis_Team);
       console.log("Get Note status "+parentthis_Team.model.get('status_c'));
       note_status =parentthis_Team.model.get('status_c');
          //console.log("This here is Parent"+);     
          
          //Note OLD vs NEW Status comparision
          
          if( note_status == "Review")
          {
  error_status =true;
  //TRY 1
             errors['description'] = errors['description'] || {};
           errors['description'].required = true;
            callback(null, fields, errors);
  }
  else
   {
console.log("MAIN CASE STATUS FIELD DOES NOT MATCH);
  }
          
           
         }
     });   

this.listenTo(noteCaseTeam,'sync',function(){

if(error_status)
{
  //TRY 2
  errors['description'] = errors['description'] || {};
           errors['description'].required = true;
            callback(null, fields, errors);
  }
  else
  {
  
   }

  });
    //TRY 3
     console.log("IN LISTEN TO PART INNER");
    errors['description'] = errors['description'] || {};
           errors['description'].required = true;
            callback(null, fields, errors);
},
    


=================

Outcomes