Sage 100 button link - pass variable to vbscript for shell call

SUGGESTED

From Main Item Maint Panel

I added a button link to run a vbscript, which runs a shell command.

How can I pass the ItemCode to the vbscript.


' init vars

Dim itemcode
Dim oShell

itemcode = "S-209220"        'hardcoded here works, but needs to change based ion item selected in ItemMaint

itemcode = CI_ItemCode_bus_ItemCode$    'this blows, what are my options


Set oShell = CreateObject("WScript.Shell")
oShell.Run "\\192.168.40.39\Library\Scripts\apps\sage_console.exe" + " " + itemcode

Regards

  • 0

    Dim itemcode
    Dim oShell

    ***BELOW** INIT FIXED THE PROBLEM

    itemcode = ""    'forgot to init the variable before assignmentItemMaint

    itemcode = CI_ItemCode_bus_ItemCode    'removed the end $ corrected the variable passing


    Set oShell = CreateObject("WScript.Shell")
    oShell.Run "\\192.168.40.39\Library\Scripts\apps\sage_console.exe" + " " + itemcode

  • 0 in reply to sevendogzero

    Spoke too soon. No value coming from Sage. Not surprised

  • 0 in reply to sevendogzero
    SUGGESTED

    You added it to the variables list in the button settings?

  • 0 in reply to Kevin M

    Wits end..even though at one point I swear it worked.

    Sage 100 Button script calling the below vbs script, which calls the shell powershell script. The script is running on the client because the output of the powershell script needs to be displayed to the user.

    Set WshShell = WScript.CreateObject("WScript.Shell")

    Dim item_code
    item_code = ""
    item_code = "S-201140"

    WshShell.run("powershell -executionpolicy bypass -noexit -file c:\Work\slab_status.ps1" & " " & item_code)

    The error 424 when running is Object required 'WScript'     script line 26

    Error clipboard below

    MS Script Link Error Information

    User... MM-2012-MAS-DEV
    Date... 8/6/2022
    Time... 17:07:00

    OLE Error Number... 424
    Description........ Object required: 'WScript'
    Language........... VBScript

    Script Line........ 26
    Script Column...... 0


    1 : '
    2 : ' Sage 100 ERP system variables
    3 : '
    4 : MAS_SCR_CMP = "SNJ"
    5 : MAS_SCR_USR = "bret"
    6 : MAS_SCR_MOD = "I/M"
    7 : MAS_SCR_DTE = "20220806"
    8 : MAS_SCR_HWD = "C:\Sage\Sage 100 Advanced ERP\MAS90\home"
    9 : MAS_SCR_LWD = "C:\Sage\Sage 100 Advanced ERP\MAS90\soa"
    10 : MAS_SCR_LIB = "C:\Sage\Sage 100 Advanced ERP\MAS90\IM\IM_ITEM.M4L"
    11 : MAS_SCR_PNL = "dMain"
    12 : MAS_SCR_OBJ = "BT_LINK_3"
    13 : MAS_SCR_MSG = ""
    14 : MAS_SCR_PFM = ""
    15 : MAS_SCR_CS = 1
    16 : MAS_SCR_DBG = 0
    17 : MAS_SCR_ERR = 0
    18 : '
    19 : ' form variables passed in by Customizer
    20 : '
    21 : '
    22 : ' language : VBScript
    23 : ' file name : \\mm-2012-mas-dev\work\call_slab_status.vbs
    24 : ' script begin
    25 : '
    26 : Set WshShell = WScript.CreateObject("WScript.Shell")
    27 :
    28 : Dim item_code
    29 : item_code = ""
    30 : item_code = "S-201140"
    31 :
    32 : WshShell.run("powershell -executionpolicy bypass -noexit -file c:\Work\slab_status.ps1" & " " & item_code)
    33 : '
    34 : ' script end
    35 : '

    The script runs perfect when run outside the Sage application

    I have the item_code hardcoded, but want to  get the ItemCode from the Item Maint table where the button link is located...and below code runs.

    Hoping I would be able to use   retVal = oBusObj.GetValue("ItemCode",item_code) or similar to deliver the ItemCode to the script, then passes to powershell.

    Anyway, hoping someone can get me past this,

    the powershell displays current item availablity to the user from multiple Sage companies - sample below

  • 0 in reply to sevendogzero
    SUGGESTED

    I continued to play and it's working now, but I have to test some more.

    The change I made was the location of the .vbs script from a c:\work folder (on the Sage server)

    to the ..mas90\cm\scripts folder.

    Still holding my breath, but the item code is being captured and pass to the powershell script, and the results are being displayed to the user

    Maybe I'm dreaming,

    Bret