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.

  • 0
    SUGGESTED

    I figured it out. I needed to drop the Shipping Data Entry object before posting. Here is a working snippet:

    # Post SO Invoices
    $retVal = $oSS.nSetProgram($oSS.nLookupTask("SO_SalesJournal_ui")) 
    $oSalesJournalUpd = $oScript.NewObject("SO_SalesJournal_upd",[ref]$oSS)
    
    $arrBatchesToPost = @()
    
    foreach ($sBatchNo in $arrBatch) {
        if ($sBatchNo -ne $sBatchCurr -and $sBatchNo -ne " " -and  $sBatchNo -ne "") {
            $sBatchAmt = ""
            $nBatchCnt = 0
            $retVal = $oShip.nSelectBatch([ref]$sBatchNo)
            $retVal = $oShip.nVerifyBatch([ref]$sBatchNo,[ref]$sBatchAmt,[ref]$nBatchCnt)
            if ($nBatchCnt -eq 0) {
                Write-Host "Batch $sBatchNo is empty and will be deleted."
                $oBatch = $oShip.ocoBatch()
                $retVal = $oBatch.nDelete()
                try { $oBatch.DropObject() } catch {}
            }
            else {
                Write-Host "Preparing BatchNo $sBatchNo - Invoice Count: $nBatchCnt`n$sBatchAmt`n----------"
                $arrBatchesToPost = $arrBatchesToPost + $sBatchNo
            }
            $retVal = $oShip.nClear()
        }
    }
    
    try { $retVal =$oShip.nClear();$oShip.DropObject() } catch {}
    
    $bBatchesToPost = $false
    foreach ($sPostBatch in $arrBatchesToPost) {
        $oSalesJournalUpd.sLastErrorMsg = ""
        $retVal = $oSalesJournalUpd.nSelectBatch([ref]$sPostBatch)
        if ($retVal -eq 1) {
            $bBatchesToPost = $true
        }
    }
    
    if ($bBatchesToPost -eq $true)
    {
        $retVal =$oSalesJournalUpd.nPDFSilent = 1
        $retVal =$oSalesJournalUpd.nSetPostingDate("$sModuleDate")
        $retVal =$oSalesJournalUpd.nProcessReport("PRINT") #DEFERRED
        $retVal =$oSalesJournalUpd.nEndOfPDFConverterJob()
        $retVal =$oSalesJournalUpd.nUpdate()
    }
    
    try {$oSalesJournalUpd.DropObject() } catch {}