Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / How to add validation ...
Finance forum
Suggested answer

How to add validation on form data, to date and query value

Posted on by 126
Hi Team,
 
I am creating SSRS report.
 
In dialog i am having From data, To date and query with main account.
 
I have to add validation if Main account is not blank, and from date and to date is exceeds 1 years show the warning if click Ok button in dialog.
 
Please let me know how to show the validation warning.
  • CU21091228-0 Profile Picture
    CU21091228-0 126 on at
    How to add validation on form data, to date and query value
    Below code i am using in controller class, validate method.
    protected boolean validate()
     {
         boolean        isValid = true;
         ABC_GeneralLedgerReportContract contract;
        
         contract = this.getDataContractObject();
         Query query = this.getFirstQuery();
    
        
         QueryBuildDataSource queryBuildDataSource = query.dataSourceTable(tableNum(MainAccount));
    
         QueryBuildRange queryBuildRange = queryBuildDataSource.findRange(fieldNum(MainAccount, MainAccountId));
         
         if (!queryBuildRange)
         {
             isValid  = warning("");
         }
         
    
         return  isValid;
     }
     
    In case i am not passing any value in MainAccountId, i am not able to get the warning.
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 228,792 Most Valuable Professional on at
    How to add validation on form data, to date and query value
    From date and To date are dialog fields, most likely coming from a data contract. You can easily add the validation directly to the data contract by implementing SysOperationValidatable interface and validate() method. There you'll compare the values and show a warning and return false if requirements aren't met.
     
    Main account is a query range, therefore you'll need to get the QueryBuildRange object from the query, call its value() method and check if it's empty.
     
    (Moved from Dynamics AX forum.)
  • Suggested answer
    How to add validation on form data, to date and query value in D365FO

    Assuming you have written your own controller class for the report, you should implement the 'preRunValidate' method on SrsReportRunController.
    See InventJournalTransTransferController.preRunValidate() for an example of implementation.

    In the method, you can open a dialog to prompt the user, and based on their response, you can modify the return container.


    Edit: Try to do what Martin suggested, it's way prettier. Didn't think that you might have a contract class 😀

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,572 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,792 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans