Q:

Release Invoice and Inventory Issue in code

I have a routine to release an invoice and post to inventory that worked in v6.1.   I think it was working in 2017R2 also, but I don't know for sure.   It does not seem to work at all in 2018R1.   The invoice releases, but the inventory issue is not released.   The automations are all set to automatically release the issue and they work when processed manually.   Only my code does not release the issue.   I am at a loss as to why.   Any ideas? 
============================================================
I have updated the code to the latest version based on your suggestions, but the inventory issue is still not released. 
foreach (EDASNShipment asnShipment in PXSelect<EDASNShipment,
    Where<EDASNShipment.aSNNbr, Equal<Required<EDASN.aSNNbr>>>>.Select(this, asn. ASNNbr))
{
    soShipmentGraph. Clear();
    SOShipment soShipment = soShipmentGraph. Document. Search<SOShipment.shipmentNbr>(asnShipment. ShipmentNbr);
    var soShipmentExt = PXCache<SOShipment>.GetExtension<SOShipmentExt>(soShipment);

    SOOrderShipment soOrderShipment = PXSelect<SOOrderShipment,
        Where<SOOrderShipment.shipmentNbr, Equal<Required<SOOrderShipment.shipmentNbr>>>>.Select(this, asnShipment. ShipmentNbr);

    ARInvoice arInvoice = PXSelect<ARInvoice, Where<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>,
        And<ARInvoice.docType, Equal<Required<ARInvoice.docType>>>>>.Select(this, soOrderShipment. InvoiceNbr, "INV");
    if (soShipment. Status ! = "C")
    {
        if (autoReleaseInvoices)
        {
            if (arInvoice ! = null)
            {
                /*
                soInvoiceGraph. Clear();
                soInvoiceGraph. Document. Current = arInvoice;
                soInvoiceGraph.release. Press();
                var a = new PXAdapter(soShipmentGraph. Document)
                {
                    Searches = new object[] { soShipment. ShipmentNbr }
                };
                //Note: Post Invoice to IN is Action 3 
                a.Arguments. Add("actionID", 3);
                a.MassProcess = false;                       //Don't pop up invoice screen
                a.MaximumRows = 1;
                PXLongOperation. StartOperation(this, () =>
                {
                    foreach (SOShipment shipment in soShipmentGraph.action. Press(a))
                    {
                        shipment. ShipmentNbr = shipment. ShipmentNbr;
                    }
                });
                */

                //Release Invoice
                PXLongOperation. StartOperation(this, delegate ()
                {
                    soInvoiceGraph. Clear();
                    soInvoiceGraph. Document. Current = arInvoice;
                    soInvoiceGraph.release. Press();

                    //Update IN on Shipment
                    soShipmentGraph. Clear();
                    soShipmentGraph. Document. Current = 
                            soShipmentGraph. Document. Search<SOShipment.shipmentNbr>(asnShipment. ShipmentNbr);
                    soShipmentGraph. UpdateIN.Press();
                });
            }
            else
            {
                statusText += String. Format("Acumatica Invoice could not be located: {0}  ", soOrderShipment. InvoiceNbr);
                errorOccurred = true;
                bolAtLeastOneError = true;
            }
        }
    }
    soShipmentGraph. Clear();
    soShipment = soShipmentGraph. Document. Search<SOShipment.shipmentNbr>(asnShipment. ShipmentNbr);
    soShipmentExt = PXCache<SOShipment>.GetExtension<SOShipmentExt>(soShipment);
    soShipmentExt. UsrEDIStatus = "S";       //Sent
    soShipmentGraph. Document. Update(soShipment);
    soShipmentGraph. Persist();
}

A:

After much browsing through the code repository, I found some code for releasing issues.   I adapted it to my situation and came up with the solution below which works.   I am posting it in case someone else is in a similar situation. 
if (arInvoice ! = null)
{
    //Release Invoice
    PXLongOperation. StartOperation(this, delegate ()
    {
        soInvoiceGraph. Clear();
        soInvoiceGraph. Document. Current = arInvoice;
        soInvoiceGraph.release. Press();

        //Lookup issue, add to list, and call release
        INRegister issue = PXSelect<INRegister,
            Where<INRegister.sOShipmentNbr, Equal<Required<INRegister.sOShipmentNbr>>,
            And<INRegister.docType, Equal<Required<INRegister.docType>>>>>
            .Select(this, asnShipment. ShipmentNbr, INDocType. Issue);
        //Check setup flag and issue status
        if (sosetup. Current. AutoReleaseIN == true &&
            issue. Hold == false &&
            issue. Released == false)
        {
            List<INRegister> issues = new List<INRegister>();
            issues. Add(issue);
            INDocumentRelease. ReleaseDoc(issues, false);
        }
    });
}

