Using DB via globals in custom php file

I am trying to implement some sort of javascript functionality onto a field situated in an edit view.
However, it seems like I cannot call any of the global variables in my custom php script such as the db.

What am I doing wrong?

Here’s there editview.js I am using and have allocated to the metadata of the editview vardefs in the custom folder:

$( function() {
	$("#order_id").autocomplete({
		source: "search.php",
		minLength: 3
	});
});

and here is the corresponding search.php script

<?php
if(!defined('sugarEntry')) define('sugarEntry', true);
require_once 'include/entryPoint.php';

$sql = "SELECT id, order_id FROM KAM_POData";
$result = $GLOBALS['db']->query($sql);
$order_ids = array();
while($row = $GLOBALS['db']->fetchByAssoc($result){
	$order_ids[] = array("label" => $row['order_id']);
}
echo json_encode($order_ids);

?>

I also tried to call the log in order to put out anything but that does also not work.
what do I need to import/include/require other than what I already do?

When I echo something like ["Test1, “Test2”, “Test3”] it does indeed work. But I need access to my db.

Did you register the custom entrypoint?

https://docs.suitecrm.com/developer/entry-points/

Thanks for noticing! Haven’t had done that

This is my entry point registration “additionalEntrypoint.php” located in custom/application/Ext/EntryPointRegistry

<?php
	$entry_point_registry['search_php'] = array(
		'file' => 'custom/modules/KAM_POData/js/search.php',
		'auth' => false,
	);
?>

After QRR it’s however still not working.

The system does recognize the entry point when I try to access the php via url. It puts out that an array was echo’ed. If I change the echo up into vardump it even returns the array, I would be looking for.

So it seems that the integration into the javascript prohibits the search.php from accessing the global variables and therefore also the database. Is this maybe some kind of security measurement?

Would there be any other way to integrate autocomplete functionality onto a field based on the current values from the database?

That’s not where the Docs tell you to put the file…

It should be in

custom/Extension/application/Ext/EntryPointRegistry/

and then it’s SuiteCRM that picks it up as it aggregates extension files during the QR&R, and puts it where you had placed it:

custom/application/Ext/EntryPointRegistry

(in your case, the QR&R would be clearing your definition!)

Ah, yes of course. That was a typo on my part, sorry about that. Just forget the “/Extention/” before Application.
I did however indeed put it exactly in the right folder before running QRR.

Maybe you should change:

$( function() {
	$("#order_id").autocomplete({
		source: "search.php",
		minLength: 3
	});
});

to something like:


$( function() {
	$("#order_id").autocomplete({
		source: "index.php?entryPoint=additionalEntrypoint",
		minLength: 3
	});
});

I am not sure if this will work. If not I recommend that, instead of doing it in a different way, you should follow exactly as explained in the manual page shared by @pgr

(you have changed several things so it may not work unless you know precisely what you are doing!)

1 Like

It did work in the end! Thank you so much!
However, it also proved to be very useful to clear the cache and browsing data from time to time.

How much more complicated would it be to do a regular REST call onto the API?
It seems to me that it’s just a dirty version of a functionality that is actually already given if I am not mistaken.

What was the solution that worked? (just for others in case they have a similar problem)