Skip to main content
Answer

I query PO by requisition number but always return null.

  • September 16, 2023
  • 10 replies
  • 108 views

Forum|alt.badge.img

 

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

Best answer by VardanV

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.

10 replies

darylbowman
Captain II
Forum|alt.badge.img+15

Try instance.Actions.PressSave()


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • September 18, 2023

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.


VardanV
Jr Varsity III
Forum|alt.badge.img+1
  • Jr Varsity III
  • Answer
  • September 18, 2023

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.


darylbowman
Captain II
Forum|alt.badge.img+15

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.


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • September 18, 2023

@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.


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • September 18, 2023

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

 


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • September 18, 2023

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


VardanV
Jr Varsity III
Forum|alt.badge.img+1
  • Jr Varsity III
  • September 18, 2023

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


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • September 20, 2023

Thank it solved


darylbowman
Captain II
Forum|alt.badge.img+15

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