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

PO validation when using "Late selection" from the "Confirm purchase order" screen

(0) ShareShare
ReportReport
Posted on by

I'm working with some code that uses COC handling the validate event in PurchFormLetter_PurchOrder, this works fine when confirming a single PO, this.purchTable() contains a valid record.
When attempting to use "Late selection" from the "Confirm purchase order" screen, at the point where click "Ok", the validate event fires sending in a blank record this.purchTable().recId is 0.
The batch job then runs and PO's that I want to validate with my custom logic get erroneously confirmed.
How do I ensure that all records being processed by the "Purchase order confirmation" batch job are validated individually?

public boolean validate(Object _calledFrom)
{
      boolean ret = next validate(_calledFrom);
      PurchTable  purchTable  = this.purchTable();
      //custom code here
      return ret;
}

I've also tried 

[PostHandlerFor(classStr(PurchFormLetter_PurchOrder),methodStr(PurchFormLetter_PurchOrder,validate))]
public static void PurchFormLetter_PurchOrder_Post_Validate(XppPrePostArgs args)
{
}

No dice.

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,183 Super User 2025 Season 2 on at

    Hi Daniel,

    Can you indicate what you want to achieve exactly? A confirmation of the purchase order might only update a status field. When this is in x++, it can skip the validation method. If you explain the scenario, we might be able to assist you.

  • DanAx Profile Picture
    on at

    Thanks so much for responding, I may be missing something obvious.

    I've extended PurchTable to add a custom field, this field may be blank when the PO is created but must be populated for confirmation.

    When confirming a single PO from "All purchase orders" screen, I click the "Confirm" button from the "Purchase" tab, the code below fires, this.purchTable() returns the selected line, the validation works.

    But if I go to the "Confirm purchase order" screen, choose "Late selection", click "Select", this takes me to the "Purchase update" screen that allows me to provide a filtering query for the PO's I want to confirm.  Click the "Ok" button, then click "Batch", then click "Ok", then click "Ok" again.  At this point the validate fires, but this.purchTable() is a blank object with recId == 0, so I can't validate the records that may be included in the query nor do I want to at this point, there could be one, there could be hundreds.  If I allow the validate to complete (debugging) I get a message stating "The Purchase order confirmation job is added to the batch queue.".  The batch job runs and all PO's matching the filter criteria get confirmed, the validate method does not fire for each of them.  I need to be sure my custom field is populated for each item before allowing it be confirmed.

    [ExtensionOf(classstr(PurchFormLetter_PurchOrder))]
    public final class PurchFormLetter_PurchOrder_My_Extension
    {
       public boolean validate(Object _calledFrom)
       {
           boolean     ret         = next validate(_calledFrom);
           if (ret)
           {
               PurchTable  purchTable = this.purchTable();
               if(purchTable.MyCustomField == '')
               {
                   ret = checkfailed("This needs to be populated.");
               }
           }
           return ret;
       }
    }

  • DanAx Profile Picture
    on at

    I have found something that works.

    If I catch the FinalUpdateValidation on PurchTable, I can compare the original DocumentState to the new one, if it is being changed from Approved to Confirmed, I do my validations and throw an error if my field value is missing.

    This allows valid PO's in the batch to be confirmed and throws the error on the bad ones.

    This seems to be the only event I can count on, so many of the others don't fire at all or inconsistently, like OnUpdating, OnUpdating, etc.

    Is this the correct path?

  • André Arnaud de Calavon Profile Picture
    301,183 Super User 2025 Season 2 on at

    Hi Daniel,

    In this way, it will try to confirm the order. If the state changes, you are doing your validation. For sure it works, but it will do coding which is consuming processing time. You can actually try to interact at the start of each confirmation to avoid doing a lot of computing which could end in an error. Not exactly sure which method is the best here to interact with. Potentially, you can use the debugger to see if you can achieve this. That is also what I should do to find out.

  • DanAx Profile Picture
    on at

    André, apologies for the delayed response and thanks so much for your input.  I'll have to go back and have a look at some of the other events, put a bunch of them in a class with breakpoints, FinalUpdateValidation was the only consistent one, I may have missed something and will have to go back and try again.  If you get to it before me let me know.  Thanks again for the help.

  • André Arnaud de Calavon Profile Picture
    301,183 Super User 2025 Season 2 on at

    Hi Daniel,

    Have you checked if you can use the validate() method of the class PurchFormLetter?

  • Suggested answer
    Ante Profile Picture
    5 on at

    instead of this.purchTable() you should go with the this.parmId():

    PurchTable      locPurchTable;

    PurchParmTable  purchParmTable;

           select locPurchTable

               join purchParmTable

               where purchParmTable.parmId  == this.parmId()

                  && purchParmTable.PurchId == locPurchTable.PurchId

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
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 420 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 241 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans