web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Calling a command control button from another form axtension

(0) ShareShare
ReportReport
Posted on by 172

I have a button 'OK' in ProdParmReport that I want to disable on condition. AutoDeclaration is set to NO.

My code returns object reference error in axapta. How can I call it correctly ?

[ExtensionOf(formdatasourcestr(ProdTableListPage, ProdTable))]
final class ProdParmReportFinishedActiveWG_Extension
{

    public int active()
    {
        int ret;
        next Active();
        
        {
            ProdTable tableBuffer = this.cursor();
            ProdTable prodtable;
            
       
            if(tableBuffer.ProdId == tableBuffer.InventRefId
            || tableBuffer.InventRefType == InventRefType::None
            || tableBuffer.ProdStatus != ProdStatus::ReportedFinished)
            {
                while select RecId,ProdId from ProdTable where
                ProdTable.InventRefId == tableBuffer.ProdId
                 && ProdTable.Prodstatus != ProdStatus::ReportedFinished
                {
                   // FormButtonControl mybutton = this.FormRun().design().controlname(formControlStr(ProdParmReportFinished, Ok)) as FormButtonControl;
                  //  mybutton.enabled(false);
                
                    Global::info(strFmt("%1 , %2",
                prodtable.prodid, prodtable.recid));
                }
            }
            else
            {
           
                Global::info(strFmt("%1 , %2",
                tableBuffer.prodid, tableBuffer.recid));
            }

        }
        return ret;
    }

}

I have the same question (0)
  • RadekM Profile Picture
    172 on at

    My code so far. I need to call a comand button 'OK" from a different form and create a error info for user there. 
    With my code I get just object reference error. Any idea ?

    [ExtensionOf(formdatasourcestr(ProdTableListPage, ProdTable))]
    final class ProdParmReportFinishedActiveWG_Extension
    {
    
       public int active()
        {
            int ret;
            next Active();
            
            {
                ProdTable tableBuffer = this.cursor();
                ProdTable prodtable;
                
           
                if(tableBuffer.ProdId == tableBuffer.CollectRefProdId
                     && tableBuffer.ProdStatus != ProdStatus::ReportedFinished)
                    {
                       select firstonly RecId,ProdId from ProdTable where
                    ProdTable.CollectRefProdId == tableBuffer.ProdId
                     && ProdTable.Prodstatus != ProdStatus::ReportedFinished
                        && tableBuffer.RecId != prodtable.RecId;
                    {
                            Global::info(strFmt("%1 , %2",
                    prodtable.prodid, prodtable.recid));
                        
                             FormButtonControl mybutton = this.FormRun().design().controlname(formControlStr(ProdParmReportFinished, Ok)) as FormButtonControl;
                             mybutton.enabled(false);
                    }
                       
                }
                else
                {
               
                    Global::info(strFmt("%1 , %2, %3, %4",
                    tableBuffer.prodid, tableBuffer.CollectRefProdId, tableBuffer.InventRefType, tableBuffer.ProdStatus));
                }
    
            }
            return ret;
        }
    
    }

  • Martin Dráb Profile Picture
    237,722 Most Valuable Professional on at

    I don't think that AutoDeclaration is relevant in extensions.

    Anyway, regarding dealing with your bug: debug your code to identify the place where you're trying to call methods on a null references. You can't fix the problem before finding it.

    Assuming that you gave us wrong code and actually have the code inside the while select block commented out, I can see the bug without debugging. You're extending a data source of ProdTableListPage form, but then you're trying to find a control from a different form (ProdParmReportFinished instead of ProdTableListPage).

    By the way, you again added the extra {} after next(). I'm pretty sure I already fixed that for you in your other thread. And you don't have to prefix info() with Global::. Just using info() does the same thing and it means less text to write and read.

  • RadekM Profile Picture
    172 on at

    Well yes I got a bug when I call mybutton.enabled(false);

    So if this wont work. Should I create a class extension for this form and write there a run() method ?

    How can I call this class extension from my actual form extension ?

    Or is there some other option ?

  • Martin Dráb Profile Picture
    237,722 Most Valuable Professional on at

    As the first thing, decide which of the two forms you actually want to use. Everything else depends on this decisions. For example, if you're trying to refer to control don't exist in the form you're extending, getting an error is the expected outcome.

    Please think about the overall design first and only then about code.

    Form extensions don't contain code, so they don't call anything. And you won't call the active() method of your extension class; it's called automatically by the form when you switch from one record to another. We discussed that in one of your other threads about this topic. That's why you're using active(), remember?

  • RadekM Profile Picture
    172 on at

    Can I create a global boolean value that can change his value in my select and be used in my second form extension ?

  • RadekM Profile Picture
    172 on at

    I want to use ProdParmReportFinished Form. Everything else is just to get a point to use it.

    Since my active() method runs anyway I could provide me a handler that I could use in ProdParmReportFinished but still I don't know how I could access this handler from there.

  • Martin Dráb Profile Picture
    237,722 Most Valuable Professional on at

    If you want to extend ProdParmReportFinished, fix your extension class. You are currently extending ProdTableListPage form instead of ProdParmReportFinished form.

  • Community Member Profile Picture
    on at

    try this:

    Code:

    Call Forms!FormName.buttonName_Click

  • RadekM Profile Picture
    172 on at

    Forms!FormName.buttonName_Click

    Won't work since I need to disable button not click it.

    If i fix my extension my code won't work ! ProdTable is on ProdList Extension ! How could I check the current recid ?

    If I cant access a button from ProdList in ProdParm then maybe I can send a bool? How can I do it?

    [ExtensionOf(formdatasourcestr(ProdTableListPage, ProdTable))]
    final class ProdParmReportFinishedActiveWG_Extension
    {
     
       public boolean CheckWGstatus;
    
       public int active()
        {
            int ret;
            next Active();
            ProdTable tableBuffer = this.cursor();
            ProdTable prodtable;
    
    
                if(tableBuffer.ProdId == tableBuffer.CollectRefProdId
                     && tableBuffer.ProdStatus != ProdStatus::ReportedFinished)
                    {
                       select firstonly RecId,ProdId from ProdTable where
                          ProdTable.CollectRefProdId == tableBuffer.ProdId
                          && ProdTable.Prodstatus != ProdStatus::ReportedFinished
                          && tableBuffer.RecId != prodtable.RecId;
                          {
                              CheckWGStatus = true;
                  
                          }
                    }
                else
                {
                    Global::info(strFmt("%1 , %2, %3, %4",
                    tableBuffer.prodid, tableBuffer.CollectRefProdId, tableBuffer.InventRefType, tableBuffer.ProdStatus));
                }
    
            return ret;
        }
    
        public boolean getCheckWGStatus()
        {
            return CheckWGStatus;
        }
    
    }

    [ExtensionOf(formStr(ProdParmReportFinished))]
    final class ProdParmReportFinishedWG_Extension
    {
      
        public void run()
        {
            next run();
         
            
            if(CheckWGStatus == true)
            {
                Ok.enabled(false);
                Info("@SRM:SRM00049");
            }
            else
            {
                Info('im false');
            }
        }
    
    }

  • Martin Dráb Profile Picture
    237,722 Most Valuable Professional on at

    Sure, you must fix all bugs. The code that assumes that the current form is two different forms at once is clearly wrong.

    Now you're asking the right question: how the thing that you want to achieve can be done. That's where you should have started. You're buried in random pieces of code and you don't have any plan how the implementation should work.

    The first step is thinking about the functionality from users' point of view. Then create a high-level plan of what should happen in code. If you need help with it, you must share your functional requirements with, so we can do the analysis.

    Let me guess what the requirement is:

    Users selects a record in ProdTableListPage and open ProdParmReportFinished for the selected ProdTable. Then you want to get the ProdTable in ProdParmReportFinished form. Is it correct?

    Then you're doing it wrong. You don't want to extend ProdTableListPage at all, because you don't want to change any behavior there. You don't need to pass the active ProdTable to ProdParmReportFinished, because - I assume - it already works. Isn't ProdParmReportFinished already opened for the selected ProdTable? If so, there is nothing that you need to do.

    You also don't want a current record of any datasource in ProdParmReportFinished. What you want is the ProdTable record that was passed from ProdTableListPage to ProdParmReportFinished when ProdParmReportFinished form was opened. And that can be done by getting arguments of the form and calling record() method. For example: this.args().record().

    If my guess of what you want was wrong, it's time for you to explain what it is. Let me remind you once more that showing a code snippet isn't the same thing as explaining functional requirements.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 687 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 535 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 403 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans