Issues reading values from other tables using hooks

mmaresca

New member
I have 2 issues using hooks. I have created a complete order entry and tracking system using dadabik. Works great. I have used functions with
success including automatically retrieving GPS coordinates and maps from mobile users. Here are my 2 issues.

1) As soon as I un-comment any of your examples of hooks, the program literally crashes.

2) I need to accomplish the following:
(Simple Description - as I actually have about 18 tables, but the operation I need just deals with 3 tables)

I have 3 tables: CLIENTS, ORDERS and ACCOUNT_REPS

A user creates a new order in the ORDERS table.
The ORDERS table has a field for Client_Name.
The Client_Name is selected from a single select drop down which is linked to the CLIENTS table.

That all works fine.

(Here is the issue)

In the CLIENTS table, I have a field that contains an Account_Reps_Name which is retrieved from the ACCOUNT_REPS table and populated when a new client is added to the system (CLIENT table).

When creating a new order, I need to retrieve the Account_Reps_Name from the CLIENTS table automatically when the Client is selected and insert it into a field in the ORDERS table.

I need an example or guidance on the above...


Your current DaDaBIK version​

You are using DaDaBIK version 10.3-Manarola enterprise, installed on 10-31-2020 (installation code: 161525f9d843a6507f), the latest version of DaDaBIK is 11.4-Elba released on 02-28-2022

System info​

PHP Version: 7.4.3

mysql version: 8.0.22-0ubuntu0.20.04.2

Web server: Apache/2.4.41 (Ubuntu) OpenSSL/1.1.1f

Client: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36
 

eugenio

Administrator
Staff member
Hello,

1) You should report the error you see. Also consider that you are using an old version of DaDaBIK released in Aug 2020 and since then a lot of bugs have been fixed (check the change log)

2) Don't know if it works for your use case, but I wouldn't use a hook: if each cusotmer record has its own Account_Reps_Name I would just keep it as an additional linked field for the Client_Name field in the order table.

Best,
 

mmaresca

New member
Thank you. I will try that however, I believe I already tried and it does not populate Account_Rep field automatically upon selecting
the Client_Name.
 

eugenio

Administrator
Staff member
My point is that maybe you don't need that field, it would be redundant since you already have the customer (and you can see Account_Rep from the dropdown menu)
 

mmaresca

New member
Just tried you suggestion. Still does not work. When I add the Account_Reps_Name as an additional Linked field in the Client_Name field, It places the Account_Reps_Name in the same field as the Client_Name field...

ie....Client_Name Field (Without Link): ABC Printing
Client_Name_Field (With Link): ABC Printing John Smith

In both cases, the Account_Reps_Name field in the ORDERS table is left blank.
 

mmaresca

New member
Just saw your reply. Thank You. For reporting reasons, I need to have the Account_Reps_Name in a separate field.
That is what I am trying to accomplish. Essentially populating 2 fields in table A with information from 2 fields in table B
based on one single selection field.
 

eugenio

Administrator
Staff member
I can give you some general advise, I can't provide here the full code:

1) you need both an after insert hook and an after update hook for the orders table (after update in case the user changes the customer)

2) in both hooks, you will receive in input the ID of the order, you will use it to get, with an SQL SELECT statement, the customer and therefore Account_Reps_Name from the customers table

3) finally, you will execute an SQL UPDATE query to update Account_Reps_Name in the orders table
 

mmaresca

New member
Thank you. Thats what I guess I was missing. Any Idea why the entire application crashes if I un-comment the example hooks in custom_functions.php? There is no need for me to post the error, It literally says the site is unreachable.
 

eugenio

Administrator
Staff member
If you get a 500 error or similar, probably it just means that your server is configured not to directly display the errors, you should check your web server error logs to see the actual error produced.
 

mmaresca

New member
It says xmds.php' not found or unable to stat

This only occurs if i un-comment or try to write a hook... So it must be something required by dadabik?
 
Top