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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

How to clear record in the field after triggering error message

(0) ShareShare
ReportReport
Posted on by 175

Hi there, we got an requirement to develop an lookup field for MainAccount form. As per the requirement, we need to add an condition and if that condition doesn't satisfies, i need to throw error message and clear the text in the field.  I can able to throw error message and prevent saving  it but cant able to clear record entered (after manually clearing record also still throwing error message). I had added coc for validatewrite() in my datasource table and trying to add condition from there. Please have a look at my table extension class code and suggest me accordingly.

pastedimage1631099614553v1.pngpastedimage1631099840231v2.png

I have the same question (0)
  • Suggested answer
    PK69 Profile Picture
    175 on at
    RE: How to clear record in the field after triggering error message

    That helped alot.  Thanks for the useful information.

  • ergun sahin Profile Picture
    8,812 Moderator on at
    RE: How to clear record in the field after triggering error message

    select firstOnly RecId from mainAccount
        where mainAccount.MainAccountId == this.LocalLedgerAccount
        exists join cnlLuxView 
            where cnlLuxView.Type       == mainAccount.Type;
        
    if(!mainAccount.RecId)
    {
    }

    Maybe something like this

  • Suggested answer
    ergun sahin Profile Picture
    8,812 Moderator on at
    RE: How to clear record in the field after triggering error message

    You can write the code in validateField but as Martin said the code is wrong.

    As I understand it, You want select a localAcount. Then You want to check if the type of this account exists in the custom Type table.

    In this case, you need to find the mainAccount with the localAcount you selected and join check the custom table with exists join.

    If mainAccount.RecId is empty, you can throw an error in checkFailed in validateField

    Since I do not know the relations between the tables, I cannot write in more detail, but the current query always gives the same result. It's no different than typing true or false instead of typing the query.

  • Martin Dráb Profile Picture
    225,155 Moderator on at
    RE: How to clear record in the field after triggering error message

    I'm still not convinced that your select statement is correct. What is the point of checking data unrelated to what you're saving? Why don't you specify which MainAccount you want to check and you leave to the database server? You'll effectively get data for the first main account in the database, regardless of what main account you're actually saving.

    It looks utterly wrong to me.

  • PK69 Profile Picture
    175 on at
    RE: How to clear record in the field after triggering error message

    Hi Martin, if I add any  condition to that join that the error condition is not triggering . I had type field in both MainAccount table and CNLLUXView (our customized view). The lookup field needs to validate the condition that MainAccount.Type == CNLLUXLocalAccountMapping.Type.

    And the lookup field is in MainAccountLegalEntity Table thats where am trying to add validateWrite() for our condition

    Please suggest accordingly.

  • Martin Dráb Profile Picture
    225,155 Moderator on at
    RE: How to clear record in the field after triggering error message

    It's very strange that your condition isn't related to the selected record at all - I think you forgot a 'where' condition in the query.

    Clearing LocalLedgerAccount doesn't make any difference for the condition, because it doesn't use this field.

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

Private forums Quick links

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2025 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

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

Product Insights Trigger

Product updates

Dynamics 365 release plans