Page 1 of 1

How to update detail table automatically when inputting data in master detail?

Posted: Fri Mar 22, 2024 9:34 am
by diazwahyunugraha

Is it possible to update the detail table automatically when inputting data in the master detail?

I have a master table with an x_cardnumber column then in the details there is also an x_cardnumber column with multiple records.

How do I do this when I input data in the x_cardnumber master table. the x_cardnumber in the detail table is also updated automatically


Re: Is it possible to update the detail table automatically when inputting data in the master detail?

Posted: Fri Mar 22, 2024 12:37 pm
by mobhar

Your case is a bit confusing. When you said inputting data in master table, then it means there are no data yet both for your master and detail table. How can you update the data in detail table, then?


Re: Is it possible to update the detail table automatically when inputting data in the master detail?

Posted: Fri Mar 22, 2024 8:17 pm
by diazwahyunugraha

Because i already have master table which is summary from detail table, but in the detail table there is blank field that must multiple update by field in master table

Master table:
Name, address, sumofbuy, id_card

Detail table:
Name, address, buy, id_card

Which is master table already summaries by name and by address

I need to fill id card (multiple) in detail table automaticly just by input id_card in master table


Re: Is it possible to update the detail table automatically when inputting data in the master detail?

Posted: Sat Mar 23, 2024 7:52 am
by apis

use Server Event table specific row inserted like this:

$myResult = ExecuteStatement("UPDATE MyTable SET Field1=Value1, Field2=Value2, Field3=Value3 WHERE MyField=XXX");// Row Inserted event

and if you want to input multi values use concat function


Re: How to update detail table automatically when inputting data in master detail?

Posted: Sat Mar 23, 2024 11:04 am
by mobhar

diazwahynugraha wrote:

I need to fill id card (multiple) in detail table automaticly just by input id_card in master table

Then you should use Row_Updated (not Row_Inserted) server event that belongs to your master table in order to update the related data in your detail table.


Re: How to update detail table automatically when inputting data in master detail?

Posted: Sun Mar 24, 2024 12:25 am
by diazwahyunugraha
// Row_Updated event for MasterTable
function Row_Updated(&$rsold, &$rsnew) {
    // Check if id_card field is updated
    if ($rsold['id_card'] != $rsnew['id_card']) {
        // Perform update in DetailTable based on the updated id_card value
        $detailUpdateQuery = "UPDATE DetailTable SET id_card= '{$rsnew['id_card']}' WHERE name= '{$rsnew['name]}' AND address= '{$rsnew['address]}' ";
        Execute($detailUpdateQuery);
    }
}

this error


Re: How to update detail table automatically when inputting data in master detail?

Posted: Sun Mar 24, 2024 4:02 am
by gopalverma1

Refer Documentation : Field Setup ->Client Side Event ->Example 1 & Example 2

IN MASTER TABLE FIELD : x_cardnumber (Client Side Event)

{
    "change keyup": function(e) {
		$('[data-table=DETAILTABLE][data-field=x_cardnumber]').trigger("change");
    }
}

IN DETAIL TABLE : x_cardnumber (Client Side Event)

{ // keys = event types, values = handler functions
    "change keyup": function(e) {
		var xcardnumber = myform.elements["x_cardnumber"].value;
        var $row = $(this).fields(); // Get an object of all fields, each property is a jQuery object of the input element(s) of a field
        //var st = $row["UnitPrice"].toNumber() * $row["Quantity"].toNumber() * (1 - $row["Discount"].toNumber()); // Convert to number and calculate
        $row["x_cardnumber"].value(xcardnumber); // Set result to a field
    }
}

Think this will help


Re: How to update detail table automatically when inputting data in master detail?

Posted: Sun Mar 24, 2024 3:22 pm
by mobhar

There is no need to add curly brackets in your SQL, so try this:

"UPDATE DetailTable SET id_card='".$rsnew['id_card']."' WHERE name='".$rsnew['name]."' AND address='".$rsnew['address]."'"

It that SQL doesn't work, then you need to re-evaluate your data while updating master record, especially for name and address fields, whether it will be changed or not... if those fields remain same, then you may try:

"UPDATE DetailTable SET id_card='".$rsnew['id_card']."' WHERE name='".$rsold['name]."' AND address='".$rsold['address]."'"


Re: How to update detail table automatically when inputting data in master detail?

Posted: Sun Mar 24, 2024 10:32 pm
by diazwahyunugraha

Fatal error: Call to undefined function Execute() in ...

i dont know why


Re: How to update detail table automatically when inputting data in master detail?

Posted: Sun Mar 24, 2024 10:41 pm
by mobhar

Try to use ExecuteStatement instead of Execute.