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

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 

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

    Thanks Girish for your valuable time Now its working.

  • GirishS Profile Picture
    GirishS 27,821 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
    ax.tech 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
    ax.tech 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
    GirishS 27,821 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
    ax.tech 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
    GirishS 27,821 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
    ax.tech 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
    GirishS 27,821 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
    ax.tech 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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans