Announcement

Collapse
No announcement yet.

Set boolean value for Entity

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

  • Set boolean value for Entity

    Hi Tanya,

    I tried the below line to update a boolean field (checkbox) for an entity with TRUE or FALSE values but it does not update.

    PHP Code:
    $entity->set('fieldName'true);
    $this->getEntityManager()->getRepository('Entity')->saveEntity($entity); 

  • #2
    Hello
    Set method for boolean field works, but save with $this->getEntityManager()->saveEntity($entity);
    If it's doesn't work, check your $entity (how did you get it?)

    Comment


    • #3
      I was trying to override the convert function of the Lead to Opportunity that would set specific fields in the Lead after conversion to Opportunity. Some fields are working but only the boolean fields were not. I already tried using values below but none worked.

      true
      "1"
      1
      "true"

      The below code snippet is from
      /application/Espo/Modules/Crm/Services/Lead.php
      PHP Code:
      public function convert($id$recordsData){
              
      $lead $this->getEntity($id);
              if (!
      $this->getAcl()->check($lead'edit')) {
                  throw new 
      Forbidden();        
              }          
              
      $entityManager $this->getEntityManager();
              if (!empty(
      $recordsData->Account)) {
                  
      $account $entityManager->getEntity('Account');
                  
      $account->set(get_object_vars($recordsData->Account));
                  
      $entityManager->saveEntity($account);
                  
      $lead->set('createdAccountId'$account->id);
                  
      // custom 11/27/2017            
                  
      $lead->set('isExistingAccount'true);            
                  
      $lead->set('existingAccountId'$account->id);            
                  
      // end custom        
                  
      }        
              if (!empty(
      $recordsData->Opportunity)) {
                   
      $opportunity $entityManager->getEntity('Opportunity');
                  
      $opportunity->set(get_object_vars($recordsData->Opportunity));
                  if (isset(
      $account)) {
                      
      $opportunity->set('accountId'$account->id);
                  }
                  
      // custom 11/27/2017
                  
      else if(!empty($lead->get('existingAccountId'))){
                      
      $opportunity->set('accountId'$lead->get('existingAccountId'));
                  }            
                  
      // end custom            
                  
      $entityManager->saveEntity($opportunity);
                  
      // custom 11/27/2017
                  
      if(empty($recordsData->Contact) && !empty($lead->get('existingContactId'))){
                      
      $existingContact $entityManager->getRepository('Contact')->get($lead->get('existingContactId'));
                      
      $entityManager->getRepository('Contact')->relate($existingContact'opportunities'$opportunity);
                  }            
                  
      // end custom
                  
      $lead->set('createdOpportunityId'$opportunity->id);
              }        
              if (!empty(
      $recordsData->Contact)) {
                  
      $contact $entityManager->getEntity('Contact');
                  
      $contact->set(get_object_vars($recordsData->Contact));
                  if (isset(
      $account)) {
                      
      $contact->set('accountId'$account->id);
                  }
                  
      $entityManager->saveEntity($contact);
                  if (isset(
      $opportunity)) {
                      
      $entityManager->getRepository('Contact')->relate($contact'opportunities'$opportunity);
                  }
                  
      $lead->set('createdContactId'$contact->id);

                  
      // custom 11/27/2017            
                  
      $lead->set('isExistingContact'true);
                  
      $lead->set('existingContactId'$contact->id);
                  
      // end custom
              
      }          
              
      $lead->set('status''Converted');
              
      $entityManager->saveEntity($lead);  
              
      //...  

      These lines were not working after saving entity:

      PHP Code:
      $lead->set('isExistingAccount'true);
      $lead->set('isExistingContact'true); 
      But the setting of the ID fields are working but not on the boolean fields.
      PHP Code:
      $lead->set('existingContactId'$contact->id);
      $lead->set('existingAccountId'$contact->id); 
      Last edited by brianpunzalan; 11-28-2017, 11:09 AM.

      Comment


      • #4
        Hello
        You could set this fields with formula. Your way is not upgrade safe.

        Comment

        Working...
        X