Search code examples
graphacumaticaschedule

Way to determine if within a running scheduled task?


How can I tell, within the graph processing logic, if it's being executed through a Scheduled task rather than through user interaction?

PXProcessing doesn't seem to have much, nor does the records within the AUSchedule table

Reason: If I'm in an interactive session, I want to redirect to multiple screens for the document(s) I've created. In a Scheduled task, I don't want to clutter up the server with these Redirects


Solution

  • Take a look through the code repository at SOShipmentEntry. Search for SOInvoiceEntry and it will get you to the Action function where it creates the invoice. You can see that they call the adapter.MassProcess function to see if it is running in a process or not and throws exceptions, sets info, or errors based on the status. You can also see the AllowRedirect flag in use.

    Here is an example of redirecting to the invoice at the end of a shipment invoice creation:

    SOInvoiceEntry ie = PXGraph.CreateInstance<SOInvoiceEntry>();
    ......
    ......
    if (adapter.AllowRedirect && !adapter.MassProcess && created.Count > 0)
    {
        using (new PXTimeStampScope(null))
        {
            ie.Clear();
            ie.Document.Current = ie.Document.Search<ARInvoice.docType, ARInvoice.refNbr>(((ARInvoice)created[0]).DocType, ((ARInvoice)created[0]).RefNbr, ((ARInvoice)created[0]).DocType);
            throw new PXRedirectRequiredException(ie, "Invoice");
        }
    }