This topic is locked
[SOLVED]

 getMasterRecord() Question

5/12/2020 12:21:51 PM
PHPRunner General questions
R
RBrogen author

I'm working on a field (OrderPayments_Payer) event with the code below in the server and client after sections that is on a details page of my Order Form main document. I'm looking up the client first and last name based on an ID on the main document. I can manually type in the client_ID field in the SQL select and the code works perfectly, however, when I try to get the master record and then access the client_ID field from that variable it errors out. I'm sure it's me not getting the syntax right and I'm looking for guidance and that would greatly appreciated.
SERVER SECTION

$data = $pageObject->getMasterRecord();
$rs = DB::Query("select client_FirstName, client_LastName from dbo.CLIENTS WHERE client_ID = ".$data['client_ID']);

while( $data=$rs->fetchAssoc()){

$result["clientFirstName"]=$data['client_FirstName'];

$result["clientLastName"]=$data['client_LastName'];

}
CLIENT AFTER SECTION
ctrl.setValue(result['clientFirstName'] + " " + result['clientLastName']);

Sergey Kornilov admin 5/12/2020

Step 1. What is the error message?

R
RBrogen author 5/12/2020



Step 1. What is the error message?


Sorry about that ... Server Error 500 and it stops working.

N
Nir Frumer 5/12/2020

hi,

may be you should try a space after the while
while ($data=$rs->fetchAssoc()){

$result["clientFirstName"]=$data['client_FirstName'];

$result["clientLastName"]=$data['client_LastName'];

}
hope it helps,

Sergey Kornilov admin 5/12/2020

Enable detailed error messages in web server settings so it shows the actual error message instead of generic error message 500.

R
RBrogen author 5/12/2020



hi,

may be you should try a space after the while
while ($data=$rs->fetchAssoc()){

$result["clientFirstName"]=$data['client_FirstName'];

$result["clientLastName"]=$data['client_LastName'];

}
hope it helps,


Thanks I tried that but got the same Internal 500 server error

R
RBrogen author 5/12/2020



Enable detailed error messages in web server settings so it shows the actual error message instead of generic error message 500.


Thanks Sergey. I enabled detailed error messages and this is what I got:
PHP Fatal error: Uncaught Error: Call to a member function getMasterRecord() on null in C:\inetpub\wwwroot\StudioSavvy\buttonhandler.php:1906 Stack trace: #0 C:\inetpub\wwwroot\StudioSavvy\buttonhandler.php(364): fieldEventHandler_OrderPayments_Payer_event(Array) #1 {main} thrown in C:\inetpub\wwwroot\StudioSavvy\buttonhandler.php on line 1906

Sergey Kornilov admin 5/12/2020

Thank you, makes sense. It appears that getMasterRecord() function is not available in the button's Server event but there are workarounds.
You can add the following code to BeforeProcess event of the page in question and then use $_SESSION["client_ID"] anywhere you want.

$data = $pageObject->getMasterRecord();

$_SESSION["client_ID"]=$data["client_ID"];
R
RBrogen author 5/13/2020



Thank you, makes sense. It appears that getMasterRecord() function is not available in the button's Server event but there are workarounds.
You can add the following code to BeforeProcess event of the page in question and then use $_SESSION["client_ID"] anywhere you want.

$data = $pageObject->getMasterRecord();

$_SESSION["client_ID"]=$data["client_ID"];



OOOPS Spoke too soon ... I'm still trying to get that to work. I had manually entered the client_ID and it worked but when I try to use the $_SESSION it gives me this error.
PHP Fatal error: Uncaught Error: Call to a member function fetchAssoc() on bool in C:\inetpub\wwwroot\StudioSavvy\buttonhandler.php:1908 Stack trace: #0 C:\inetpub\wwwroot\StudioSavvy\buttonhandler.php(364): fieldEventHandler_OrderPayments_Payer_event(Array) #1 {main} thrown in C:\inetpub\wwwroot\StudioSavvy\buttonhandler.php on line 1908
I'm assuming it is because it the rs is not getting a value from the DB::QUERY because the $_SESSION is not pulling the value.
$rs = DB::Query("select client_FirstName, client_LastName from dbo.CLIENTS WHERE client_ID = ".$_SESSION['client_ID']);
while ($data=$rs->fetchAssoc()){

$result["clientFirstName"]=$data['client_FirstName'];

$result["clientLastName"]=$data['client_LastName'];

}

R
RBrogen author 5/13/2020

Got it working finally! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=91288&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' /> After getting the SESSION variable properly appended I got Undefined Undefined returned which told me that the original variable was not being set. I had the code to set the session variable in the ORDER form Before Process and it actually needed to be on the details list form. THANKS FOR THE HELP SERGEY! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=91288&image=2&table=forumreplies' class='bbc_emoticon' alt=':)' />



OOOPS Spoke too soon ... I'm still trying to get that to work. I had manually entered the client_ID and it worked but when I try to use the $_SESSION it gives me this error.
PHP Fatal error: Uncaught Error: Call to a member function fetchAssoc() on bool in C:\inetpub\wwwroot\StudioSavvy\buttonhandler.php:1908 Stack trace: #0 C:\inetpub\wwwroot\StudioSavvy\buttonhandler.php(364): fieldEventHandler_OrderPayments_Payer_event(Array) #1 {main} thrown in C:\inetpub\wwwroot\StudioSavvy\buttonhandler.php on line 1908
I'm assuming it is because it the rs is not getting a value from the DB::QUERY because the $_SESSION is not pulling the value.
$rs = DB::Query("select client_FirstName, client_LastName from dbo.CLIENTS WHERE client_ID = ".$_SESSION['client_ID']);
while ($data=$rs->fetchAssoc()){

$result["clientFirstName"]=$data['client_FirstName'];

$result["clientLastName"]=$data['client_LastName'];

}

R
RBrogen author 5/13/2020

I just realized that this works perfect on a form that has been saved and you are editing but when I add a New Order, the client_FK value is not accessible this way because the record isn't saved yet. Any suggestions on accessing the value selected in a field on the form that hasn't been saved would be greatly appreciated.
Thanks



Got it working finally! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=91292&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' /> After getting the SESSION variable properly appended I got Undefined Undefined returned which told me that the original variable was not being set. I had the code to set the session variable in the ORDER form Before Process and it actually needed to be on the details list form. THANKS FOR THE HELP SERGEY! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=91292&image=2&table=forumreplies' class='bbc_emoticon' alt=':)' />