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 ( == formstr(LIQ_RegisterCashControlDetails))  

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.