Leads bean is reset before final parent display - going through Basic::getEmailAddressId() #4795

Open
opened 2026-02-20 16:24:05 -05:00 by deekerman · 0 comments
Owner

Originally created by @vaudoin on GitHub (Jul 6, 2022).

Issue

In modules containing emails (like Leads or Contacts) , the bean is reset before completing view.

I discovered this issue while I was trying to change a custom field on Leads, custom view.detail.php (display fonction). The change was lost after parent::display(); was called.

Expected Behavior

Any custom field change done on custom view.detail.php should be kept after calling parent display.

Actual Behavior

I discovered on Basic::getEmailAddressId(), called in modules with emails that the bean is reset with the call of $this->retrieve();
That induces all changes made on view.detail.php to be removed.

Possible Fix

Basic.php fonction getEmailAddressId()
I don't see the point to call retrieve() here but I might miss something. And I guess the definite fix should be more deeply analysed, to check for side effects.
But here is the fix that works, at least for me.

private function getEmailAddressId($emailField)
{
	$log = LoggerManager::getLogger();

	$this->validateSugarEmailAddressField($emailField);
	$emailAddress = $this->cleanUpEmailAddress($this->{$emailField});

	if (!$emailAddress) {
		$log->warn('Trying to get an empty email address.');
		return null;
	}

	// List view requires us to retrieve the mail so we can see the email addresses
	
	// VAU : clone $this to not call retrieve on it (that resets content)
//      if (!$this->retrieve()) {
	$copieOfThis = clone $this;
	if (!$copieOfThis->retrieve()) {

		$log->fatal('A Basic can not retrive.');
		return null;
	}
	
	$found = false;
	// VAU : call $addresses on $copieOfThis
//		$addresses = $this->emailAddress->addresses;
	$addresses = $copieOfThis->emailAddress->addresses;
	foreach ($addresses as $address) {
		if ($this->cleanUpEmailAddress($address['email_address']) === $emailAddress) {
			$found = true;
			$emailAddressId = $address['email_address_id'];
			break;
		}
	}

	if (!$found) {
		// Changed exception to error as demo data is never selected.
		$log->fatal('A Basic bean has not selected email address. (' . $emailAddress . ')');
		return null;
	}

	return $emailAddressId;
}

Steps to Reproduce

  1. Add a custom view.detail.php on Leads module.
  2. On display() function add a change on a custom field, for instance
function display()
{
  $this->bean->my_custom_field_c = 'THE TEST';
  parent::display();
}
  1. The change is lost on the view.

Context

We could probably discuss

Your Environment

  • SuiteCRM Version used: 7.12.4
  • Environment name and version: PHP 7.3
Originally created by @vaudoin on GitHub (Jul 6, 2022). #### Issue In modules containing emails (like Leads or Contacts) , the bean is reset before completing view. I discovered this issue while I was trying to change a custom field on Leads, custom view.detail.php (display fonction). The change was lost after parent::display(); was called. #### Expected Behavior Any custom field change done on custom view.detail.php should be kept after calling parent display. #### Actual Behavior I discovered on Basic::getEmailAddressId(), called in modules with emails that the bean is reset with the call of $this->retrieve(); That induces all changes made on view.detail.php to be removed. #### Possible Fix Basic.php fonction getEmailAddressId() I don't see the point to call retrieve() here but I might miss something. And I guess the definite fix should be more deeply analysed, to check for side effects. But here is the fix that works, at least for me. ``` private function getEmailAddressId($emailField) { $log = LoggerManager::getLogger(); $this->validateSugarEmailAddressField($emailField); $emailAddress = $this->cleanUpEmailAddress($this->{$emailField}); if (!$emailAddress) { $log->warn('Trying to get an empty email address.'); return null; } // List view requires us to retrieve the mail so we can see the email addresses // VAU : clone $this to not call retrieve on it (that resets content) // if (!$this->retrieve()) { $copieOfThis = clone $this; if (!$copieOfThis->retrieve()) { $log->fatal('A Basic can not retrive.'); return null; } $found = false; // VAU : call $addresses on $copieOfThis // $addresses = $this->emailAddress->addresses; $addresses = $copieOfThis->emailAddress->addresses; foreach ($addresses as $address) { if ($this->cleanUpEmailAddress($address['email_address']) === $emailAddress) { $found = true; $emailAddressId = $address['email_address_id']; break; } } if (!$found) { // Changed exception to error as demo data is never selected. $log->fatal('A Basic bean has not selected email address. (' . $emailAddress . ')'); return null; } return $emailAddressId; } ``` #### Steps to Reproduce 1. Add a custom view.detail.php on Leads module. 2. On display() function add a change on a custom field, for instance ``` function display() { $this->bean->my_custom_field_c = 'THE TEST'; parent::display(); } ``` 3. The change is lost on the view. #### Context We could probably discuss #### Your Environment * SuiteCRM Version used: 7.12.4 * Environment name and version: PHP 7.3
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/SuiteCRM-SuiteCRM#4795
No description provided.