Saturday, February 26, 2011

Checking to see if caller is a form

I had this requirement the other day to set the filter value on the LedgerJournalTable form when it was called from a new form that had been created.

This new form contained a JournalId field and I wanted the users to be able to right-click goto main table to open the LedgerJournalTable showing the journal record.

Because the journal may or may not be posted I needed to set the standard filter on the LedgerJournalTable form to show all journals (by default when the form is opened it shows 'Open' Journals only) So, I added some code to the init method of the LedgerJournalTable form to check the element.args().caller().name for my new form and then set the filter.

This worked a treat, except I managed to break the journal lookups in other areas of the system e.g. Vendor transactions -> Original document.

To cut a long story short the Original Documents function is a class (which does not have a name() method that also calls the LedgerJournalTable form.

To get around this issue I used the code below which checks to see if the caller is a form before calling the name() method.

 if (element.args() && element.args().caller())  
 {  
     // Make sure this was via a form.  
     if(SysDictClass::is(element.args().caller(), classnum(FormRun)))  
     {  
         // Cast the caller and make sure it is the right form.  
         callerForm = element.args().caller();  
   
         if (callerForm.name() == formstr(LIQ_RegisterCashControlDetails))  
         {  
             allOpenPostedField.selection(AllOpenPosted::All);  
         }  
     }  
 }  

7 comments:

  1. nice blog.looking forward to see more of such informative postings.
    MS Dynamics Online Training

    ReplyDelete
  2. Thanks for sharing this wonderful content.its very useful to us.I gained many unknown information, the way you have clearly explained is really fantastic.keep posting such useful information.
    oracle training in chennai

    oracle training institute in chennai

    oracle training in bangalore

    oracle training in hyderabad

    oracle training

    hadoop training in chennai

    hadoop training in bangalore


    ReplyDelete
  3. I have a mission that I’m just now working on, and I have been at the look out for such information.
    data science course in malaysia

    ReplyDelete
  4. Good deep dive! This check for whether the caller is a form is super helpful for maintaining safe method calls in AX.
    best cosmetic surgeon in hyderabad

    ReplyDelete
  5. Great post! Determining when a method’s caller is a form rather than a class helps avoid runtime errors and ensures the correct workflows execute in Microsoft Dynamics AX. At Vedanta Hospitals, a trusted Cardiology Hospital in Kadapa, we also implement checks in our systems to ensure that processes kick off only under the right conditions—whether that’s ensuring the right data is accessed or the right team is engaged for treatment. Just like validating the caller prevents logic errors, validating treatment flows prevents care mistakes.

    ReplyDelete