This topic is locked

getMasterRecord retrieving the wrong record?

11/1/2023 7:06:19 PM
PHPRunner General questions
D
druck281 author

Greetings!

I am working on a detail page with Master info displayed at the top. I added a button in the header of the Master info section that should redirect the user to the edit page for the master record. I tried using getMasterRecord to get the ID from the master record and insert it into the URL for redirect but instead of getting the ID for the current Master Record, I get the ID for the first record in the master table. The master table has a PK field called "id_tngCourse".

For the purpose of debugging, I just have the URL being displayed on the screen instead of actually redirecting...

In the custom button, I have the following:

Client Before

//Empty

Server

$data = $button->getMasterRecord();
$result["CourseID"]=$data["idtng_Course"];

Client After

var message = "tng_acourse_edit.php?editid1=" + result["CourseID"];
ajax.setMessage(message);

img alt

Any ideas why I am getting the wrong ID?

Thanks!

C
cristi 11/2/2023

Your primary key field is written "id_tngCourse" and when you get the array data for that field to assign it you use $data["idtng_Course"]....it should be $data["id_tngCourse"].

admin 11/2/2023

Looks like a typo in a key column name, id_tngCourse vs idtng_Course

D
druck281 author 11/4/2023

You're right about the typo but unfortunately, the typo was in the description, not the code.

admin 11/4/2023

I guess you need to post your project to Demo Account and contact support directly.

D
druck281 author 11/4/2023

Uploaded to support...Thanks all.

B
bkrulan 11/10/2023

Did you find a solution to this problem?

I am having the same issue with the getMasterRecord function where it is returning the first record in the Master Table instead of the record on the Master-Detail Page.

I am trying to do something similar with redirecting to another URL depending on which Master Record the Detail is linked to.

Any help would be appreciated.

Thanks!

admin 11/10/2023

The issue @druck281had was related to the fact that master table SQL query had GROUP BY in it. Removing group by solved the issue.

D
druck281 author 11/11/2023

I worked with it last night and changed up the SQL query on the table to eliminate the GROUP BY clause but the problem persisted. Still working to find where I am going wrong.

admin 11/11/2023

My recommendation is to enable SQL debugging to see what SQL query is executed to get that master record and this can point you in the right direction.

fhumanes 11/12/2023

Hello,

Only, as inspiration, to debug code and debug access to database of mysql:

Greetings,
fernando

admin 11/12/2023

Just a quick follow-up. One of our customers had a similar issue with getMasterRecord() function and this is how they resolved it:

I figured it out and it was a silly mistake. I had the button located within the Master Table at the top of the Master List page. When I moved it to next the Add New button, it is querying correctly.