SO SalesJournal Update via BOI - retVal = 0 in nSelectBatch

SUGGESTED

Experts,

I am working on a script that modifies the comment on a batch, sets it to private, and eventually attempts to post batches. I am getting the following error message when attempting to do the nSelectBatch on the SO_SalesJournal_upd object:

"The status of one or more batches has changed. Verify the current status and try again."

I added nVerifyBatch right before I try to add the batch to the update process, but that doesn't change anything. I assume that the batch is still tagged as in use.

Does anyone have an idea how I can make sure the batch is not in use and can be properly updated?

# Post SO Invoices
$retVal = $oSS.nSetProgram($oSS.nLookupTask("SO_SalesJournal_ui")) 
$oSalesJournalUpd = $oScript.NewObject("SO_SalesJournal_upd",[ref]$oSS)
    
foreach ($sGLBatch in $arrBatch) {
    if ($sGLBatch -ne $sBatchCurr -and $sGLBatch -ne " " -and  $sGLBatch -ne "") {
        $sBatchAmt = ""
        $nBatchCnt = 0
        $retVal = $oShip.nSelectBatch([ref]$sGLBatch)
        $retVal = $oShip.nVerifyBatch([ref]$sGLBatch,[ref]$sBatchAmt,[ref]$nBatchCnt)
        $retVal = $oShip.nClear()
        Write-Host "Preparing BatchNo $sGLBatch - Invoice Count: $nBatchCnt`n$sBatchAmt`n----------"
        $oSalesJournalUpd.sLastErrorMsg = ""
        ##### THE NEXT LINE IS THE ONE THAT FAILS
        $retVal = $oSalesJournalUpd.nSelectBatch([ref]$sGLBatch)
    }
}

if ($retVal -eq 1)
{
    $retVal =$oSalesJournalUpd.nPDFSilent = 1
    $retVal =$oSalesJournalUpd.nSetPostingDate("$sModuleDate")
    $retVal =$oSalesJournalUpd.nProcessReport("PRINT") #DEFERRED
    $retVal =$oSalesJournalUpd.nEndOfPDFConverterJob()
    $retVal =$oSalesJournalUpd.nUpdate()
}

try {$oSalesJournalUpd.DropObject() } catch {}  

Thanks,

B.