Solved

I query PO by requisition number but always return null.

  • 16 September 2023
  • 10 replies
  • 83 views

Userlevel 3
Badge

 

I create PO from this code

            RQRequisitionEntry instance = PXGraph.CreateInstance<RQRequisitionEntry>();
            instance.Document.Current = ii;
            instance.createPOOrder.Press();
            instance.Document.Current.OpenOrderQty = new Decimal?(0M);
            instance.Document.Current.Released = new bool?(true);
            instance.Document.Current.Status = "E";
            instance.Document.Update(instance.Document.Current);
            instance.Save.Press();

And after I debug the requisition.ReqNbr have value but query always return null

POOrder pOOrder = SelectFrom<POOrder>.Where<POOrder.rQReqNbr.IsEqual<@P.AsString>>.View.Select(this.Base, requisition.ReqNbr);

 

and check database value of this po is still null. I think instace.Save.Press() not save to database yet. So how to save po to db

icon

Best answer by vardan22 18 September 2023, 08:18

View original

10 replies

Badge +11

Try instance.Actions.PressSave()

Userlevel 3
Badge

When I don’t query in the same time process of create po, I can query the result. I mean if query by another action out of the process po code.

Userlevel 4
Badge +1

Always getting a “null” result is normal, and moreover, it is the correct result to your request(in the same process). 
When you trigger the createPOOrder action with "instance.createPOOrder.Press();" it will run the PXLongOperation, meaning the code you wrote after calling the create PO order action will run before the purchase order is created and the requested purchase order will return you a 'null' result since the purchase order has not been created yet.
To get the correct result, you need to override the ProcessToPOOrder method in RQRequisitionEntry and write the code after the baseMthod call.

Badge +11

I misunderstood the issue. To further clarify what @vardan22 said, the PXLongOperation will run the createPOOrder in a concurrent thread

meaning the code you wrote after calling the create PO order action will run before the purchase order is created and the requested purchase order will return you a 'null' result since the purchase order has not been created yet.

He is in fact entirely correct.

Userlevel 7
Badge +18

@kevinheng21   Did you debug and check? After   instance.createPOOrder.Press();  line,  instance.Document.Current will become NULL, if I’m not wrong and no values will be saved in the database.

Userlevel 3
Badge

the po record is null in database until i click ok with exception error when i query select

 

Userlevel 3
Badge

Always getting a “null” result is normal, and moreover, it is the correct result to your request(in the same process). 
When you trigger the createPOOrder action with "instance.createPOOrder.Press();" it will run the PXLongOperation, meaning the code you wrote after calling the create PO order action will run before the purchase order is created and the requested purchase order will return you a 'null' result since the purchase order has not been created yet.
To get the correct result, you need to override the ProcessToPOOrder method in RQRequisitionEntry and write the code after the baseMthod call.

how to await pxlongoperation finish and query select

Userlevel 4
Badge +1

Always getting a “null” result is normal, and moreover, it is the correct result to your request(in the same process). 
When you trigger the createPOOrder action with "instance.createPOOrder.Press();" it will run the PXLongOperation, meaning the code you wrote after calling the create PO order action will run before the purchase order is created and the requested purchase order will return you a 'null' result since the purchase order has not been created yet.
To get the correct result, you need to override the ProcessToPOOrder method in RQRequisitionEntry and write the code after the baseMthod call.

how to await pxlongoperation finish and query select

You can await using the following code PXLongOperation.WaitCompletion(this.Base.UID).

But this is BAD practise. As I wrote above you can override the ProcessToPOOrder method in RQRequisitionEntry and you will recevie more readable and compact code

Userlevel 3
Badge

Thank it solved

Badge +11

Could you mark Vardan's answer as the Best Answer?

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved