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
  • 0
    SUGGESTED

    Don't have any experience using PS to do what you are doing but it looks like you enclosed some of your variables passed to various methods in double quotes and others you did not.

    Assuming those variables should not be enclosed in double quotes, it looks like the method is receiving the literal value instead of the variable's value. I've quoted the lines in question below.

    $oScript.Init("$sPathHome")

    $retVal = $oSS.nSetDate("$sModule","$sModuleDate")

    $retVal = $oSS.nSetModule("$sModule")

    $oProg = $oScript.NewObject("$sProgram", $oSS)

  • 0 in reply to David Speck

    Thanks for the response David!

    In your quotes 1 to 3 I want to get the value of the variables. So the double quotes should be fine. In PowerShell double quotes will return the variable value while single quotes will return the variable name as a string.

    In the last one I have to provide the value of the string variable $sProgram. That should be fine as well. The second part is the actual object that I need to pass in. What do you think should be changed?

Reply
  • 0 in reply to David Speck

    Thanks for the response David!

    In your quotes 1 to 3 I want to get the value of the variables. So the double quotes should be fine. In PowerShell double quotes will return the variable value while single quotes will return the variable name as a string.

    In the last one I have to provide the value of the string variable $sProgram. That should be fine as well. The second part is the actual object that I need to pass in. What do you think should be changed?

Children