Static Lookup Select Value Problem

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
ebinnasir
User
Posts: 103

Static Lookup Select Value Problem

Post by ebinnasir »

Hello,

I need a little help. In my project, i am working on master-detail table where 1 master table(finish_fabric_receive) is connected with 2 detail tables( finish_fr_insights & finishfab_return). Multiple detail table is not enabled here. I created two otheroptions button for seperate master-detail add. In the master table a static lookup field named activities_type. I want when user open finish_fabric_receive & finish_fr_insights (master-detail) add form then user get only Fabric Receive as the option and when user open finish_fabric_receive & finishfab_return (master-detail) add form then user get 2 option like Fabric Return and Batch Return. For this I put the below codes on Table Specific->Lookup_Selecting of master table:

if (CurrentPageID() == "add") {
if ($this->getCurrentDetailTable() == "finish_fr_insights") {

    if ($fld->Name == "activities_type") 
        $fld->Lookup->UseLookupCache = false; 
        $fld->Lookup->setOptions([
            ["Fabric Receive", "Fabric Receive"]
            
        ]); 
    }
    else if ($this->getCurrentDetailTable() == "finishfab_return") {
        if ($fld->Name == "activities_type")
        $fld->Lookup->UseLookupCache = false; 
        $fld->Lookup->setOptions([
            ["Fabric Return", "Fabric Return"],
            ["Batch Return", "Batch Return"]
            
        ]); 
    }
}

I see that, what ever add form open then user get last 2 select option. but if i refresh add form then actual select open appear. Same case is happening on both form. Can experts please help me to find out the mistakes?

Regards


mobhar
User
Posts: 11726

Post by mobhar »

I think you don't need to repeat twice for checking the field name. You should check it once along with the current page id checking.

After that, inside that block, you may check again the detail table name, then write your code to display the static lookup select value according to related detail table.


ebinnasir
User
Posts: 103

Post by ebinnasir »

As per your suggestion, i make below changes in coding:

if ((CurrentPageID() == "add") && ($fld->Name == "activities_type")) {

    if ($this->getCurrentDetailTable() == "finish_fr_insights") {
        $fld->Lookup->UseLookupCache = false; 
        $fld->Lookup->setOptions([
            ["Fabric Receive", "Fabric Receive"]
            
        ]); 
    }
    else if ($this->getCurrentDetailTable() == "finishfab_return") {
        $fld->Lookup->UseLookupCache = false; 
        $fld->Lookup->setOptions([
            ["Fabric Return", "Fabric Return"],
            ["Batch Return", "Batch Return"]
            
        ]); 
    }
}

Whatever the form i open first show all last 2 options.


mobhar
User
Posts: 11726

Post by mobhar »

That happened because getCurrentDetailTable method will return the detail table name that will be derived from a session variable, which is too late when checked inside Lookup_Selecting server event of master table.

So, the solution is by simply changing $this->getCurrentDetailTable() to Get("showdetail") as follows:

    if ((CurrentPageID() == "add") && ($fld->Name == "activities_type")) {     
        if (Get("showdetail") == "finish_fr_insights") {
            $fld->Lookup->UseLookupCache = false; 
            $fld->Lookup->setOptions([
                ["Fabric Receive", "Fabric Receive"]
            ]); 
        }
        else if (Get("showdetail") == "finishfab_return") {
            $fld->Lookup->UseLookupCache = false; 
            $fld->Lookup->setOptions([
                ["Fabric Return", "Fabric Return"],
                ["Batch Return", "Batch Return"]
            ]); 
        }
    }

ebinnasir
User
Posts: 103

Post by ebinnasir »

Thanks,

Your suggestion solved my problem. I am facing relevant problem with dynamic lookup. Codes are given below:

if ((CurrentPageID() == "add" || $this->isGridAdd()) && ($fld->Name == "item_description")) {

        if (Page("grey_febric_receive")->contract_id->FormValue == "Sample") {
        $fld->Lookup->UseLookupCache = false;  
        $fld->Lookup->setOptions(ExecuteRows("SELECT item_name AS lf, item_name AS df FROM item_description_list"));
        }
        else if (Page("grey_febric_receive")->contract_id->FormValue != "Sample") {

        $fld->Lookup->UseLookupCache = false; 
        $fld->Lookup->setOptions(ExecuteRows("SELECT item_description AS lf, item_description AS df FROM orderinsights"));
        
    }
    }

    if ((CurrentPageID() == "edit" || $this->isGridEdit()) && ($fld->Name == "item_description")) {

        if (Page("grey_febric_receive")->contract_id->CurrentValue != "Sample") {
            $fld->Lookup->UseLookupCache = false; 
        $fld->Lookup->setOptions(ExecuteRows("SELECT item_description AS lf, item_description AS df FROM orderinsights")); 
        }
        else if (Page("grey_febric_receive")->contract_id->FormValue == "Sample") {

        $fld->Lookup->UseLookupCache = false; 
        $fld->Lookup->setOptions(ExecuteRows("SELECT item_name AS lf, item_name AS df FROM item_description_list"));
    }
    }

The above code works properly on edit mode but when add mode data are retrieving only from $fld->Lookup->setOptions(ExecuteRows("SELECT item_description AS lf, item_description AS df FROM orderinsights")); this query for both cases. Can you please take a look why data are not properly fatching on add record mode.

Thanks


mobhar
User
Posts: 11726

Post by mobhar »

Please note that in Add Page, there are no data yet when the form is loaded. It is a blank form. That's why your code won't work for Add Page.

However, if you meant Add Page is equal to the Copy Page, then you should use EditValue instead of FormValue, for example:

if ($this->contract_id->EditValue == "Sample") { // assume contract_id uses Textbox, not Combobox control

Post Reply