Announcement

Collapse
No announcement yet.

entity->isAttributeChanged Problem

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

  • entity->isAttributeChanged Problem

    Hi there,

    I'm checking the phone. The same phone number can be once. I'm using before After method.
    For example, when editing a Lead, I change the status, but it still behaves like the phone is being edited.
    This error is coming if I click on the edit. No problem if I just click on Edit Status. Here is the sample line of code.

    Code:
    public function beforeSave(Entity $entity, array $options = array())
    {        
        $entityType = $entity->getEntityType();
        $fieldName = 'phoneNumber';
    
        $phone = preg_replace("/[^0-9]/", "", $entity->get($fieldName));
    
        $entityList = array('Lead', 'Meeting', 'Contact', 'Call', 'Customer');
    
        if(in_array($entityType, $entityList)) {
            if (!$entity->isNew()) {
                if($entity->isAttributeChanged($fieldName)) {
                    $this->checkPhoneNumber($phone, $entityType, $fieldName);                    
                }
            }else{
                if($phone) {
                    $this->checkPhoneNumber($phone, $entityType, $fieldName);
                }
            }
        }
    }
Working...
X