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

Notifications

Announcements

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)
  • GirishS Profile Picture
    27,829 Moderator on at

    Hi ax.tech,

    Can you elaborate more? You want this validation when creating new sales order?

    You said need to exit the form if the customer belongs to CFR - Which form we want to exit?

    Thanks,

    Girish S.

  • Suggested answer
    Deepak Agarwal Profile Picture
    8,602 on at

    To achieve you may need to write code at two place. Better to write code in a separate table method and call it where needed. 

    1. While creating new SO , you get option to select customer in dialog box, (SalesCreateOrder) and when selecting customer account your validation/logic needs to trigger. 

    2. On salesTable form where user can still change the customer, when modifying this field, you can trigger your logic. 

  • ax.tech Profile Picture
    86 on at

    Hi Girish,

    Yes we need validation when we create a new sales order.

    Form Name is Sales Table. Do i have to write validation in validate write method of the related table which is custtable?

    Regards

  • Suggested answer
    GirishS Profile Picture
    27,829 Moderator on at

    You can write it in SalesCreateOrder dialog form - Add your logic in validateWrite method of SalesTable DataSource. So, this method will be called whenever you click on ok button on SalesCreateOrder dialog form.

    Thanks,

    Girish S.

  • ax.tech Profile Picture
    86 on at

    Ok Girish can you please help me write this code according to logic.

    Thanks and Regards

  • Suggested answer
    GirishS Profile Picture
    27,829 Moderator on at

    Refer to the below code. Check whether its work for your scenario.

    public boolean validateWrite()
    {
        boolean ret;
        ret = super();
        if(SalesTable.CustGroup == "CFR")
        {
            ret = checkfailed("throw error");
        }
        if(salesTable.custGroup != "CFR")
        {
            if(salesTable.DlvTerm == "" || salesTable.FreightCharge == "")
            {
                ret= checfailed("throw error");
            }
        }
        return ret;
    }

    Thanks,

    Girish S.

  • ax.tech Profile Picture
    86 on at

    Thanks alot Girish for your valuable time.

  • GirishS Profile Picture
    27,829 Moderator on at

    Please take time to mark the answers as verified if it's solved your issue.

    so, others can make use of this thread.

    Thanks,

    Girish S.

  • ax.tech Profile Picture
    86 on at

    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

  • GirishS Profile Picture
    27,829 Moderator on at

    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.

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…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 679 Super User 2026 Season 1

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 332 Super User 2026 Season 1

#3
Martin Dráb Profile Picture

Martin Dráb 238 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans