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, ...
Suggested Answer

Validate SalesOrderLines when confirming the order

(1) ShareShare
ReportReport
Posted on by 1,965
Hi,
 
When confirming the sales order, i want to add a logic to fail the confirmation of the order when a certain case happens. Where is the best place to put this check??
 
The validation is related to salesLine
I have the same question (0)
  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at
    Hi, You can create an extension class for 'SalesFormLetter_Confirm' class. Create CoC  (chain of command) on validate method and add your validations there.
     
    In addition, you can refer to this Ax 2012 article for purchase order confirmation validations
     
     
  • Suggested answer
    Kevin Xia Profile Picture
    Microsoft Employee on at
    Hi,
    Depending on your question, it seems that you have questions about where to do the check. There are two ways:
    1. Event Handler: You can create a pre-validation event handler that triggers before the sales order confirmation process starts. In the event handler, you can implement your custom logic to check for the specific condition that would result in a failed confirmation. If the condition is met, you can throw an exception or display an error message to prevent the confirmation.

    2. Workflow: If you prefer a configuration-based approach, you can use a workflow to validate the sales order confirmation. Create a workflow that runs before the confirmation process, and add the necessary conditions and actions to check for the specific case. If the condition is not met, you can stop the workflow, preventing the confirmation.

    Best regards,
    Kevin
  • .. Profile Picture
    1,965 on at
    Hi all,
     
    My validation is related to salesLines and not header.
    So if i'm going to put it at validate then it means i need to loop through all lines..is there a better place?
  • .. Profile Picture
    1,965 on at
    Hi,

    So the requirement is to do some validations on each sales line before confirming the order.
    if the enum XType value is Must, then an error should be returned.
    However, if the XType value is option, then a warning should appear but, the process should proceed.

    I did this, but i have two issues/concerns:

    1. Is this the best place to perform such validation? and if it's the best place, shall i use _calledFrom for anything?
    2.  i want all warnings to appear, but currently the first warning would only be returned and it won't continue and return all warnings. So for example if the Xtype is optional for all lines in the sales order, then i want all warnings to appear, so that after confirming the user can look at all warnings and amend the value
     
    [ExtensionOf(classStr(SalesFormLetter_Confirm))]
    final class SalesFormLetter_ConfirmX_Extension
    {
        public boolean  validate(Object _calledFrom)
        {
            boolean ret;
            
            ret = next validate(_calledFrom);
    
            if(ret)
            {
                SalesLine salesLine;
                while select salesLine where salesLine.SalesId == this.salesTable().SalesId
                {
                    TableX tableX;
                    select firstonly tableX where tableX.ItemId == salesLine.ItemId;
                    if(tableX)
                    {
                        this.validateFirstField(salesLine, tableX);
                        this.validateSecondField(salesLine, tableX);
                    }
    
                }
            }
    
            return ret;
        }
    
        public void validateFirstField(SalesLine _salesline, TableX _tableX)
        {
            if(_tableX.FirstField == XType::Must && _salesLine.FirstField== '')
            {
                throw error(strFmt("The FirstField for itemId: %1, must be filled", _salesLine.ItemId));
            }
            else if(_tableX.FirstField== XType::Optional && _salesLine.FirstField== '')
            {
                checkFailed(strFmt("The FirstField for itemId: %1,  is preferred be filled", _salesLine.ItemId));
            }
        }
    
        public void validateSecondField(SalesLine _salesline, TableX _tableX)
        {
            if(_tableX.SecondField == XType::Must && _salesLine.SecondField == '')
            {
                throw error(strFmt("The SecondField for itemId: %1,  must be filled", _salesLine.ItemId));
            }
            else if(_tableX.SecondField == XType::Optional && _salesLine.SecondField == '')
            {
                checkFailed(strFmt("The SecondField for itemId: %1,  is prefered be filled", _salesLine.ItemId));
            }
        }
    }
    
     
  • André Arnaud de Calavon Profile Picture
    300,904 Super User 2025 Season 2 on at
    Hi IntegrationBeginner,
     
    This question is almost the same as your other question: PurchLines validation when confirming the oder - Dynamics Community Forum Thread Details.
    The only difference would be having a validation on the sales lines versus purchase order lines.

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

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 348 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans