Show master info in detail page

Master file (hdr)
id
code
name
infom1
infom2
infom3
infom4

created_at
updaetd_atdetail file (itm)
master_id → refer master file id
detail_id
infod1
infod2How to show selected master field in detail pages (via add / edit customtemplate)
hdr.code (ro)
hdr.name (ro)
hdr.infom1 (ro)
hdr.infom2 (ro)
hdr.infom3 (ro)
itm.infod1 (rw)
itm.infod2 (rw)ro → read only
rw → read write

You may actually use Page_DataRendering server event that belongs to the Add or Edit page, in order to display information at the top of page via $header variable in that event.

In Page_DataRendering server event, If the master table name is ‘customers’, what is the global variable for the table?

Assume you want to get the value of name field, then try:Container(“customers”)->name->CurrentValue

mobhar wrote:

Assume you want to get the value of > name > field, then try:> Container(“customers”)->name->CurrentValue

For your information, above code not working, nothing printed.

Did you use Master/Detail or single Detail list page?

mobhar wrote:

Did you use Master/Detail or single Detail list page?

Master/Detail in list page and the detail also manage to show the Master Record Page → CustomTemplate format.

You may then post your code for more discussion.

function Page_DataRendering(&$header)
{
    // Example:
    //$header = "your header";
    $hdr = [];
    $datas = [
        'test' => ['Test', 'Double Confirm'], // Test only, dummy
        'code' => ['Code', Container("customers")->code->CurrentValue], // code field in customers file (Master)
        'name' => ['Name', Container("customers")->name->CurrentValue], // name field in customers file (Master)
    ];
    $pattern = '<div id="r_%s" class="mb-3 row"><label for="x_%s" class="col-sm-2 col-form-label">%s</label><div class="col-sm-10">%s</div></div>';
    foreach ($datas as $key => $vals) {
        $hdr[] = sprintf($pattern, $key, $key, $vals[0], $vals[1]);
    }
    $header = "\n".implode("\n", $hdr)."\n";
}

I adjusted your code sufficiently so that I implemented it in Page_DataRendering server event that belongs to orderdetails table of demo2022 project, and it works properly. I can see the OrderID and CustomerID value from orders table in orders/orderdetails (Master/Detail) List page.

	$hdr = [];
	$datas = [
	'test' => ['Test', 'Double Confirm'], // Test only, dummy
	'code' => ['Code', Container("orders")->OrderID->CurrentValue], // OrderID field in customers file (Master)
	'name' => ['Name', Container("orders")->CustomerID->CurrentValue], // CustomerID field in customers file (Master)
	];
	$pattern = '<div id="r%s" class="mb-3 row"><label for="x%s" class="col-sm-2 col-form-label">%s</label><div class="col-sm-10">%s</div></div>';
	foreach ($datas as $key => $vals) {
		$hdr[] = sprintf($pattern, $key, $key, $vals[0], $vals[1]);
	}
	$header = "\n".implode("\n", $hdr)."\n";

Apologize, this code:
OrderID field in customers file (Master)should be:
OrderID field in orders file (Master)and this code:
CustomerID field in customers file (Master)should be:
CustomerID field in orders file (Master)

Still not working in add/edit page…mobhar wrote:

You may actually use > Page_DataRendering > server event that belongs to the Add or Edit page, in order to display information at the top of page via > $header > variable in that event.

Initially you did mention in Add/Edit page, but your latest example is for List page. No issue for list page but not for Add / Edit page.

Master/Detail in list page and the detail also manage to show the Master Record Page → CustomTemplate format.

That code won’t work in single Add or Edit page, unless you modify it by yourself.

I used ExecuteRow() to get those data and show in Add / Edit Single Page.Btw, can we also get the ‘User Values’ for the field and save into $array. then display $array[$rs['fieldname]] for particular field?

Always try it by yourself first, and you may post your code for more discussion.

Anyway, can think about how to load it.Better keeping all ‘User Values’ into a table and later use lookup table feature to load it. More convenience right?

Right. To get more advanced usage, it is recommended to use Lookup Table.

Hello, I tried your code in View Page, but still no value return from Master table.

// Page Data Rendering event
function Page_DataRendering(&$header)
{
	$hdr = [];
	$datas = [
	'itemlink' => ['ItemLink', Container("checks")->ItemLink->CurrentValue],
	'quantity' => ['Quantity', Container("checks")->Quantity->CurrentValue],
	'shipaddress' => ['ShipAddress', Container("checks")->ShipAddress->CurrentValue],
	];
	$pattern = '<div id="r%s" class="mb-3 row"><label for="x%s" class="col-sm-2 col-form-label">%s</label><div class="col-sm-10">%s</div></div>';
	foreach ($datas as $key => $vals) {
		$hdr[] = sprintf($pattern, $key, $key, $vals[0], $vals[1]);
	}
	$header = "\n".implode("\n", $hdr)."\n";
}

It won’t work in View page.scs wrote:

I used ExecuteRow() to get those data and show in Add / Edit Single Page.