Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Validate SalesOrderLines when confirming the order

(1) ShareShare
ReportReport
Posted on by 1,273
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
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,735 Super User 2024 Season 2 on at
    Validate SalesOrderLines when confirming the order
    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.
  • .. Profile Picture
    .. 1,273 on at
    Validate SalesOrderLines when confirming the order
    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));
            }
        }
    }
    
     
  • .. Profile Picture
    .. 1,273 on at
    Validate SalesOrderLines when confirming the order
    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?
  • Suggested answer
    Kevin Xia Profile Picture
    Kevin Xia Microsoft Employee on at
    Validate SalesOrder confirmation
    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
  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,550 Super User 2024 Season 1 on at
    Validate SalesOrder confirmation
    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
     
     

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,735 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans