This topic is locked

Copy child records

11/12/2017 2:13:22 PM
PHPRunner General questions
R
rtownsend author

Hello all,
Could someone please verify if the code on this topic will work with version 9.8? This is exactly what I need to do for my app. I'm using PHPRunner, not ASPRunner, not sure if that is part of the issue.

Thanks for any help.
Here's the link to the code: Copy child recods
On the Orders table in the After Record Added Event include this code:

if ( $_SESSION["copyid1"]!=0)

{

// debbugging Echo "not equal zero";

global $conn;

$str = "select OrderID, ProductID, Quantity, CustCode from `order details` where OrderID =".$_SESSION["copyid1"];

$rs = db_query($str,$conn);

while($data = db_fetch_array($rs))

{

$strInsert = "insert into `order details` (OrderID, ProductID, Quantity, CustCode) VALUES ('".$values["OrderID"]."','".$data["ProductID"]."','".$data["Quantity"]."','".$data["CustCode"]."')";

db_exec($strInsert,$conn);

}

}

//header("Location: order_details_list.php?mastertable=orders&masterkey1=".$keys["OrderID"]);

//header("Location: order_details_list.php?mastertable=orders&masterkey1=" . $keys["OrderID"]);

// ********** Send simple email ************

$email=$_SESSION["emailID"];

$from="ordersdb@ACME.com";

$msg="Your Order has been received";

$subject="ACME Order Recieved";

//foreach($values as $field=>$value)

//{

// if(!IsBinaryType(GetFieldType($field)))

// $msg.= $field." : ".$value."\r\n";

//}
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];
$_SESSION["copyid1"] = 0;


In the Add Page before Process have this code to flag for the copy:



if (@$_REQUEST["copyid1"])

$_SESSION["copyid1"] = $_REQUEST["copyid1"];
romaldus 11/12/2017

i have only one question:

why you select and insert data from and into the same table (select from order details and than insert into order details)?
cmiiw

R
rtownsend author 11/12/2017

Thanks for the reply. As a non-programmer, I thought this code would work for my needs. After spending all day disecting it, I've come to the conclusion that it may not be.
Here is what I need to accomplish.
I have 3 tables - Demographics, Soap, and Soap_dx_info.
Demographics is a master. Soap is its detail. Soap_dx_info is a detail of Soap.
When the user clicks on the copy button while on the Soap listing, I need it to pull up the record on the edit screen (which it does) and ALSO bring over the associated records in the Soap_dx_info table. It currently does not bring over the Soap_dx_info detail records.
I don't want anything written into the database unless the user clicks the Save button.
Hopefully this makes sense.
Thanks for any help you can provide.
Russ

romaldus 11/12/2017

To copy detail records of selected record in master page (copy records from soap to soap_dx_info):In PHPRunner visual editor, in demographics list page, create a new button on top of list page (click insert code, insert button).
Double click button,

  1. Delete all sample code in "client before" tab
  2. In server tab, use the following code to copy selected

global $dal;while ( $data = $button->getNextSelectedRecord() ) {

$sql = "INSERT INTO soap_dx_info(field1, field2, field3, field4,)SELECT field1, field2, field3, field4 FROM soapWHERE soap.your_linked_key_field = '".$data["key_field"]."'";CustomQuery($sql);

}$result["txt"] = "Copy Records Done.";


Note : Linked key field is a field in soap table which is linked to master table primary key
3. In "client after tab" :



var message = result["txt"];

ctrl.setMessage(message);
location.reload();


R
rtownsend author 11/13/2017

Thanks for the reply.
The code appears to be copying from Soap into Soap_dx_info.
What I need is to copy a selected Soap record and all of its associated Soap_dx_info detail records onto a New Soap Record page.
Side note - the code that you sent has the "Copy record done" appear below the button when it is clicked, but nothing is added to the database.
Thanks.