Strange error when accessing records

I briefly explain the type of error:
when I try to access a record in a custom module, a blank page appears with an error message "an error has occurred. Please try again later’.
I should point out that until recently there was no problem and nothing has changed. it’s as if the problem is related to this specific laptop.
I have also tried logging in from this laptop with administrator credentials and the result is the same, whereas from other machines, trying with user credentials and administrator credentials, there is no problem. No errors appear in suitecrm.log
Can you give me an explanation? Thank you.

This is the version of Suite:

Version 7.10.20
Sugar Version 6.5.25 (Version 344)

Did you check php_errors.log?

And the browser’s developer console?

i was checking the browser’s developer console and it gives error 500 on ajaxui, which is strange because it was working until recently. the browser is Microsoft Edge

Error 500 probably means your server

a) crashed
OR (more likely)
b) had a PHP Fatal error

… which will show in your php_errors.log

I solved it, I cleared the cache of Microsoft Edge and it worked. Thanks PGR

1 Like

I am resuming this discussion because, the problem continues and I have to clear the cache every time.
I think I figured out the problem, I entered in logic_hook:

$hook_array[‘process_record’] = Array();
…

and this loops the linked subpanels, within the custom module.

In php_error log:

PHP Fatal error:  Uncaught Error: Call to a member function format() on bool in C:\xampp\htdocs\suitecrm\custom\modules\<CUSTOM_MODULE>\Highlight.php:20
Stack trace:
#0 C:\xampp\htdocs\suitecrm\include\utils\LogicHook.php(272): Highlight->highlightIndustry(Object(<CUSTOM_MODULE>), 'process_record', NULL)
#1 C:\xampp\htdocs\suitecrm\include\utils\LogicHook.php(208): LogicHook->process_hooks(Array, 'process_record', NULL)
#2 C:\xampp\htdocs\suitecrm\data\SugarBean.php(3109): LogicHook->call_custom_logic('<CUSTOM_MODULE>', 'process_record', NULL)
#3 C:\xampp\htdocs\suitecrm\include\ListView\ListViewSubPanel.php(299): SugarBean->call_custom_logic('process_record')
#4 C:\xampp\htdocs\suitecrm\include\ListView\ListViewSubPanel.php(159): ListViewSubPanel->process_dynamic_listview_rows(Array, Array, 'dyn_list_view', '<CUSTOM_MODULE_PARENT>...', Object(aSubPanel))
#5 C:\xampp\htdocs\suitecrm\include\SubPanel\SubPanel.php(220): ListViewSubPanel->process_dynamic_listview('<CUSTOM_MODULE_PARENT>', Object(<CUSTOM_MODULE> in C:\xampp\htdocs\suitecrm\custom\modules\<CUSTOM_MODULE>\Highlight.php on line 20

You must have some bug in your hook code, can you share it?

this is the contents of the file called by logic_hook:

if (! defined('sugarEntry') || ! sugarEntry)
	die ('Not A Valid Entry Point');

class Highlight{

    public function highlightIndustry(SugarBean $bean, $event, $arguments){
		global $db;
						
		$id_cicle=$bean->RELATIONSHIP_ida;
		$t_cicle_g=$bean->t_cicle_g;
				
		$data = DateTime::createFromFormat('d/m/Y', $bean->data);		
		$data=$data->format('Y-m-d');
		
	
		
		if($id!='' AND $data!=''){		
			
			$qry_datain="SELECT MAX(data_in) as datain, t_cicle_int FROM crp_cicle_int WHERE id_cicle = '".$id_cicle."' AND data_in <= '".$data."' AND deleted=0";
			
			$resultin=$db->query($qry_datain);
			
			if($db->getRowCount($resultin)){
				$datain = $db->fetchByAssoc($resultin);
				
				$t_cicle_int = $datain['t_cicle_int'];
				$datain=$datain['datain'];
				
				if($t_cicle_g>$t_cicle_int){					
					$colour = 'ff5733'; 
					$bean->data = "<div style='border: solid 10px #$colour;'>".$bean->data."</div>";
				}
			}
			
							
			$qry_datain="SELECT MAX(data_in) as datain, t_cicle_ext FROM crp_cicle_ext WHERE id_cicle = '".$id_cicle."' AND data_in <= '".$data."' and deleted=0";
			$resultin=$db->query($qry_datain);
			
			if($db->getRowCount($resultin)){
				$cicle_res = $db->fetchByAssoc($resultin);
				 
				$t_cicle_ext = $cicle_res['t_cicle_ext'];
				$datain=$cicle_res['datain'];
				
				if($t_cicle_g>$t_cicle_ext){					
					$colour = 'ffa500'; 
					$bean->data = "<div style='border: solid 10px #$colour;'>".$bean->data."</div>";
				}
										 
			}
						
			
		}	
    }
}

Your bug is in line 20, as the error says, in the format command.

That is probably caused by the previous line, which is not returning a proper value; maybe you meant to use $bean->date instead of $bean->data ?

No, the name is right, maybe there is something wrong with the date at all, yet I printed on the screen both before the conversion and after and everything is okay, I don’t understand what is bothering

Check the data type in your IDE (or using var_dump which also prints types)

Maybe your $bean->data is type string when you thing it is a PHP datetime.

the $bean->data field is of type Date

Note that your variable $data is evolving through different data types in your code.

But the error is here:

$data = DateTime::createFromFormat('d/m/Y', $bean->data);

At this point, it’s expecting $bean->data to be a string.

This is returning bool (my bet is it’s false) so the command on the next line fails because format is not a valid method of false :slight_smile:

At this point, it’s expecting $bean->data to be a string.

If successful, after the second command, $bean->data would be a DateTime object.

How do I solve it? I tried it this way:
$data=(string)$data->format(‘Y-m-d’);
but it doesn’t change anything

No, not there, the problem is earlier.

Something like

$data = DateTime::createFromFormat('d/m/Y', SomeWayOfMakingThisAStringThatTheFunctionWillUnderstand($bean->data));

I’m not sure if a simple cast will be enough. Try a few different things and see what works.

I think I spotted the problem, some dates result NULL and I don’t know why, $bean->date doesn’t contain any values (but it should), I had to put checks, the only filled value is $bean->name which also contains the date.
Crazy round to get it (with explode), but for now it seems to work (at least it doesn’t error), I will have to test it thoroughly