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

X++ validation

(0) ShareShare
ReportReport
Posted on by 1,215

Hi guys,

 

i have a custom form and i have created Credit and Debit fields.

now, i want to if i gives credit and debit at the time debit i need it both of one skip by default

how can i write in x++ and i got a standard logic is there a GetPost method used on it. 

Thanks,

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    I don't fully understand your question but you can write validation code in following places:

    - validateWrite() method of the table

    - validateField() method on the table

    - validateWrite() method of the form data source

    - validate() method of the form data source field

    If you need more specific help, could you try to explain what you mean by "if i gives credit and debit at the time debit i need it both of one skip by default"

  • Riyas ahamed F Profile Picture
    1,215 on at

    Thanks for your replay,

    i  don't want at the time two value debit and credit once i give it to credit and debit both of one field skip  we want so that how can i write in x++.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    I don't understand what you mean by "skip".

    If you want to validate and prevent user from inputtind debit and credit, put this code in the validateWrite() method of the table:

    public boolean validateWrite()
    {
        boolean ret= super();
        
        if (ret)
        {
            if (myTable.CreditField && myTable.DebitFiel)
            {
                 ret = checkFailed("My error message");
            }
        }
        
        return ret;
    }

  • Riyas ahamed F Profile Picture
    1,215 on at

    Thanks

    but, i want to

    Ex : in the Ledger journal credit and debit is there a Credit and Debit both of value one value 'cleared'

    same action we need in my custom form.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    In this case I suggest looking at that form / table and use it as an example in your implementation. Whenever you want to implement something similar than what you see in the standard system, just look at the standard implementation.

    There's quite a bit of logic on the journal but in the end handling of those two fields is very simple. In the modified method of each (form data source) field, check if the field has value and if it has, clear the other field.

  • Riyas ahamed F Profile Picture
    1,215 on at

    it is not quite a bit logic also i tried same way it is did't work for me blow my code

    in this code called in GotFoucs both of field. 

     void setDebCredProposal(boolean _init)
        {
            if (_init)
            {
                debCredProposal = DebCredProposal::None;
            }
    
            if (debCredProposal != debCredProposalOld)
            {
                switch (debCredProposal)
                {
                    case DebCredProposal::Credit  :
                         RIY_Bankrequest_AmountCurDebit.skip(true);
                        break;
    
                    case DebCredProposal::Debit   :
                          RIY_Bankrequest_AmountCurCredit.skip(true);
                        break;
    
                    case DebCredProposal::None    :
                        RIY_BankRequest_AmountCurCredit.skip(false);
                        RIY_Bankrequest_AmountCurDebit.skip(false);
                        break;
                }
                debCredProposalOld = debCredProposal;
            }
        }

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Your code seems to do something completely else than what you described earlier. And it completely ignores my suggestion of hooking in the modified method of the data source fields. Earlier you wrote that if user inputs value in debit field, credit field should be cleared / emptied. And vice versa.

    But now you seem to have some "DebCredProposal" field which you are using.

    I suggest that you spend a bit more time trying to clarify your requirement to yourself and to us.

    IF your requirement is this: "in the Ledger journal credit and debit is there a Credit and Debit both of value one value 'cleared'. same action we need in my custom form." then you should hook in the modify methods of your Debit/Credit fields in the form data source.

    modified method of debit field:

    public void modified()
    {
        super();
        
        if (myTable.DebitField)
        {
            myTable.CreditField = 0;
        }
    }

    modified method of credit field:

    public void modified()
    {
        super();
        
        if (myTable.CreditField)
        {
            myTable.DebitField = 0;
        }
    }

  • Riyas ahamed F Profile Picture
    1,215 on at

    Thanks a lot,

    but, in this code won't work for me what could be the reason same you suggested as i wrote a FormdataSouce filed  <modified() it is might be any properties or what did i mistake.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    For me it works. Could you share your code - this way it's much easier to spot mistakes in it :)

  • Riyas ahamed F Profile Picture
    1,215 on at

    
            [DataField]
            class AmountCurCredit 
            {
                /// 
                ///
                /// 
                public void modified()
                {
                    RIY_BankRequest bankRequest;
                    super();
                    if(bankRequest.AmountCurCredit)
                    {
                        bankRequest.AmountCurDebit = 0;
                    }
                }
    
            }
    
            [DataField]
            class AmountCurDebit 
            {
                /// 
                ///
                /// 
                public void modified()
                {
                    RIY_BankRequest bankRequest;
                    super();
                    if(bankRequest.AmountCurDebit)
                    {
                        bankRequest.AmountCurCredit = 0;
                    }
                }
    
            }
    

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 646 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans