BOI in Microsoft PowerShell

SOLVED

I am trying to use PowerShell instead of VBScript to access Sage via BOI. I am able to login, set the company, set the module and get a handle to the table I want. But I am not able to retrieve values when looping through the table. I tried multiple variations but can't get it to work. The retVal for nGetValue is 1, but nothing comes back.

Has anyone successfully used the BOI via PowerShell?

Here is the relevant part of my code:

$sUser = "*******"
$sPW = "*********"
$sCompany = "ABC"
$sModule = "P/O"
$sPathHome = "C:\Sage\Sage100v2017\MAS90\Home"
$sUIObject = 'PO_PurchaseOrderInquiry_Ui'
$sProgram = 'PO_PurchaseOrder_svc'

...

Write-Host "Logging into Sage 100`n"
#Create COM-Object for Sage, log in, set company, module, and program
$oScript = New-Object -ComObject ProvideX.Script
$oScript.Init("$sPathHome")
$oSS = $oScript.NewObject("SY_SESSION")
$retVal = $oSS.nlogon()

if ($retVal -eq 0) {
$retVal = $oSS.nSetUser($sUser, $sPW)
}

if ($retVal -eq 0) {Write-Host "Execution stopped | Error:" $oSS.sLastErrorMsg(); $oSS.nCleanUp(); $oSS.DropObject(); Exit}

if (-not $oProg) {
#Get Current Date and format for ModuleDate
$sModuleDate = Get-Date -format "yyyyMMdd"

$retVal = $oSS.nSetCompany($sCompany)
if ($retVal -eq 0) {Write-Host "Execution stopped | Error:" $oSS.sLastErrorMsg(); $oSS.nCleanUp(); $oSS.DropObject(); Exit}

$retVal = $oSS.nSetDate("$sModule","$sModuleDate")
if ($retVal -eq 0) {Write-Host "Execution stopped | Error:" $oSS.sLastErrorMsg(); $oSS.nCleanUp(); $oSS.DropObject(); Exit}
Write-Host "nSetDate $retVal"

$retVal = $oSS.nSetModule("$sModule")
if ($retVal -eq 0) {Write-Host "Execution stopped | Error:" $oSS.sLastErrorMsg(); $oSS.nCleanUp(); $oSS.DropObject(); Exit}
Write-Host "nSetModule $retVal"


$retVal = $oSS.nSetProgram($oSS.nLookupTask($sUIObject))
if ($retVal -eq 0) {Write-Host "Execution stopped | Error:" $oSS.sLastErrorMsg(); $oSS.nCleanUp(); $oSS.DropObject(); Exit}
Write-Host "nSetProgram $retVal"
$oProg = 0
$oProg = $oScript.NewObject("$sProgram", $oSS)
}

#$oSS | Get-Member -MemberType Method
#$oScript | Get-Member -MemberType Method
#$oProg | Get-Member -MemberType Method

$testPO = ""
$oProg.nMoveFirst()
$retVal = $oProg.nGetValue('PurchaseOrderNo$',$testPO)

Write-Host "$retVal | PO: $testPO"

Parents Reply Children