Script to transfer data to secondary company

Is it possible to write data into different company within some Sage 100 company. For Example add a button on Sales Order Entry to copy order to secondary company.

I know how to do it outside of Sage with a script but not sure  if session to different company can be created from UDS.

Thanks

  • 0

    Two Ideas: No 1 is if you already know how to do this a BOI script running outside the Launcher (outside of Sage), you can certainly click / execute a BOI button inside the Launcher, that is inside S/O Entry, that runs practically the same code to create your order for a secondary company. (This is commonly seen as creating a SO in 1 company and a drop-ship PO in the 2nd).

    You just can't re-use the same internally passed in vars for UDS. IOW if your BOI button script today uses oSession for the session object, change it to oSS or similar. The reason is oSession is now referencing the SO Entry session on the screen for current company whilst your oSS is for the 2nd company. Same if you use oScript in your BOI. Change that to oPvxScript or similar so you can use for the 2nd company. oScript is for the SO Entry session on the screen for current company. Hope that made sense.

  • 0

    No 2: It might be possible with UDS (no BOI) since you don't need to also pop the screen for S/O Entry in the secondary company.

    *** You'd have to test this idea thoroughly though. I haven't tried it myself ***

    Let's say you're sitting in in S/O Entry in company 001 and want to duplicate the current order new order to company 002. Assume 002 is setup identically to 001.

    Probably best to run script on Table Post-Write but develop it as a button first. It might have to stay as a button for that matter. Here is the general idea the premise of which is the SetCompany() method.

    ** Again I haven't tested it but seems plausible **

    'Store all your Company 001 values in variables that you want to copy into the 002 order
    'For the Lines in 001 consider creating an array to loop thru to store the fields of data you want to copy over to 002

    'When ready to create order in 002:

    'Switch to 002 company
    rSetDupeCompany = oSession.SetCompany("002")
    If rSetDupeCompany Then

    oSO = oSession.GetObject("SO_SalesOrder_bus") 'can't use oBusObj it belongs to 001
    If oSO <> 0 Then Set oSO = oSession.AsObject(oSO)
    Set oSOLines = oSO.AsObject(oSO.Lines) 'can't use oLines it belongs to 001

    retVal = oSO.GetNextSalesOrderNo(sNextSO) 'this should happen in 002 now
    rVal = oSO.SetKey(sNextSO) 'this should happen in 002 now
    If rVal = 2 Then 'EditState of 2 means ready to create new order in 002

    'Use oSO.SetValue() for necessary Header and Address tab fields you need to set

    'Start a Lines loop array that will copy from the 001 company lines array you created earlier to repetitively do:
    'oSOLines.AddLine()
    'oSOLines.SetValue() on ItemCode, QuantityOrdered, etc
    'even better use SetValues() here instead of individual SetValue()
    'oSOLines.Write()

    'oSO.SetValue() for any Totals tab fields you need to override
    'retVal = oSO.Write()
    'If retVal = 0 Then r=oScript.DebugPrint("Error on 002 Write: " & oSO.LastErrorMsg)

    End If

    'Switch back to 001 company
    rSetDupeCompany = oSession.SetCompany("001")

    End If

  • 0

    My first thought would be to use the button to create a text file with the data, then write a batch file with the commands for starting a pre-configured VI import using the correct company code, then trigger the newly created batch file.

    Not as elegant and seamless as Alnoor's answer, but easy to do.