How to call mysqli


I’m trying to use the MySQL database of our suitecrm instance , but i have no idea how to call a mysqli. For example call a mysqli from a logic_hook[after_save].

Any guidance is greatly appreciated.

Shouldn’t you be using the Beans to access your data?

You can also use direct SQL, but it is not recommended:

if you choose to use direct MySQL-queries, please consider that specific framework-features will be skipped (like logic hooks/workflows/validations).
Therefore, in case that’s an option, use beans like pgr suggested. Maybe you can describe what you’re trying to do more detailed?

Here is a sample on how to call run queries from a logic hook:



Hey, i’m soory for the late reply.

Thank you for the replies people.

The thing i am trying to achieve is a connection between CRM and another webapp. Every time an account is created in CRM it send a api request to the web app with all the fields from $bean. The request then returns a unique id from the webapp., this Id is required for any future PATCH or PUT requests to the webapp to modify that specific record. That unique Id returned from api is then stored in the Account record in a custom field.

All of this above works really well.

The next step is to have the same thing but for an AOS_Invoices. This is where my problem begins… For some reason i am unable to access the $bean of any created Invoice in CRM.
Not even something very simple. [event hook: after_save]

 //if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
 //include_once __DIR__ . "/../../SimpleApi.php";
 class processInvoice {
 function InvoiceRequest($bean, $event, $arguments) {
 $bean->ett_c = $bean->id;

I need to be able to access the custom field with the webapp’s Id to that specific customer. In the Accounts module from the chosen relate Account field when creating an invoice, in order to create usable request to the webapp.

I don’t know if the AOS_Invoices are a bit different in constructing the $bean on creation. because while i was trying to understand the process of the $bean creation in Invoices. I thought i stumbled on a the problem while using xdebug in my vscode, and having a SSH tunnel to my CRM instance the $bean object didn’t contain any usable fields, only after 2 requests from executing custom_logic via Hooks.
I can follow up on that if requested.

Anyway i think for this topic i guess @AlxGr replied with the solution.

Thanks again for the replies!