Skip to main content

 

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

Try instance.Actions.PressSave()


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.


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.


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.


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


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

 


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


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


Thank it solved


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


Reply