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, ...
Answered

How to put validation in sales order?

(0) ShareShare
ReportReport
Posted on by 86

H Experts,

I have to write a condition on a sales table form in which :

1. I have check is the customer belong to "CFR" group or not 

2. If the customer belongs to CFR group we have to exit but if the customer is not from CFR group we have to check Delivery Term if found then we have to ask for Freight charge.

Please help thanks in advance

Regards 

I have the same question (0)
  • ax.tech Profile Picture
    86 on at
    RE: How to put validation in sales order?

    Thanks Girish for your valuable time Now its working.

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: How to put validation in sales order?

    Code again is wrong.. I already said that you can add that code in datasource validate method at form level. So you can easily get the values.

    Also in the above code you have declared the salesTable buffer - but where you will get the value for that buffer?

    Thanks,

    Girish S.

  • ax.tech Profile Picture
    86 on at
    RE: How to put validation in sales order?

    public boolean validateWrite()
    {
        boolean ret;
        SalesTable salesTable;
    
        ret = super();
        
        if(salesTable.custGroup != "CFR")
          {
            if(salesTable.DlvTerm == "DT007" || salesTable.DlvTerm == "DT008" || salesTable.DlvTerm == "DT009" || salesTable.DlvTerm =="DT012" || salesTable.DlvTerm == "DT077")
            {
                if(this.FreightCharge == 0)
                {
                    ret = checkfailed("Fright charge must be filled in");
                }
            }
          }
    
        return ret;
    }

    Hi Girish,

    I am still not getting "Fright charge must be filled in" when i create a new sales order. I have written above code into validatewrite method of abcsaleslinetable which is a custom table(Used This) in which i have created freight charge field. Do i have to add find method for sales also to get this error message please help correct this code.

    Regards

  • ax.tech Profile Picture
    86 on at
    RE: How to put validation in sales order?

    Thank you so much Girish for your time It means alot.

  • Verified answer
    GirishS Profile Picture
    27,825 Moderator on at
    RE: How to put validation in sales order?

    It seems now you have changed the scenario. Initially you didn't talk about hard coding delivery term values. Try the below code.

    public boolean validateWrite()
    {
        boolean ret;
        ret = super();
        
        if(salesTable.custGroup != "CFR")
        {
            if(salesTable.DlvTerm == "DT007" || salesTable.DlvTerm == "DT008" || salesTable.DlvTerm == "DT009" || salesTable.DlvTerm =="DT012" ||salesTable.DlvTerm == "DT077")
            {
                if(salesTable.FreightCharge == "")
                {
                    ret - checkfailed("Fright charge must be filled in");
                }
            }
        }
     return ret;
    }
       
    

    Thanks,

    Girish S.

  • ax.tech Profile Picture
    86 on at
    RE: How to put validation in sales order?

    Hi Girish,

    In the given code you are throwing an error if the customer group is not "CFR" and the freight charge code condition which we do not want our scenario. Can you Please write correct code - scenario is we have to throw "Freight charge must be filled in" if the customer group is not  and CFR and delivery term code belongs to "DT007" , "DT008" , "DT009", "DT012" , "DT077" these.

    Thanks and Regards

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: How to put validation in sales order?

    Have you tested this?

    Is it working?

    I have written code based on the scenario you asked but you are not following the code. Is the code wrong or it doesn't meet your scenario?

    Thanks,

    Girish S.

  • ax.tech Profile Picture
    86 on at
    RE: How to put validation in sales order?

    public boolean validateWrite()
    {
        boolean      ret;
        SalesTable   salesTable;
        ret = super();
        
        if(salesTable.custGroup != "CFR")
        {
            if(salesTable.DlvTerm == "DT007" || salesTable.DlvTerm == "DT008" || salesTable.DlvTerm == "DT009" || salesTable.DlvTerm =="DT012" ||salesTable.DlvTerm == "DT077")
            {
                ret= checkfailed("Freight charge must be filled in");
            }
        }
        return ret;
    }

    Hi Girish,

    Is it correct now ?

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: How to put validation in sales order?

    You have written this in SalesTable datasource validateWrite method. So, you need to validate the current record when creating new sales order. But you are validation is wrong.

    Just follow the code which I have sent in my previous reply. It will work for your scenario.

    Thanks,

    Girish S.

  • ax.tech Profile Picture
    86 on at
    RE: How to put validation in sales order?

    public boolean  validateWrite()
    {
        boolean            ok = true;
        salesline         salesline;
        DlvTerm            dlvTerm;
    
        ok = super();
        ok = ok && this.validateWriteServer();
    
        if((this.CustGroup != "CFR") && (dlvTerm.Code == "DT007" || dlvTerm.Code== "DT008" || dlvTerm.Code== "DT009" || dlvTerm.Code== "DT012" || dlvTerm.Code== "DT077" ))
        {
            ok = checkfailed("Freight charge must be filed in");
        }
    
        return ok;
    }

    Hi Girish,

    I have written this code "code" is the delivery term code which is coming from dlvTerm table. Please correct me where i am wrong as this code is not running. I am not getting any error. Please help

    Regards

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 777 User Group Leader

#2
André Arnaud de Calavon Profile Picture

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

#3
Martin Dráb Profile Picture

Martin Dráb 602 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans