Sage 100

 View Only
  • 1.  Sage 100 Scripting accessing SO Header info from SO Details script

    Posted 04-30-2020 11:54
    Hi there,

    I have a script that fires on Sales Order Details event Column- Post validate Item Code Field.

    In this script I need to access the Customer Price level on the a/r customer record to do some pricing calculations. (may or may not be same as what defaults on line level price level as user could change that on a per line basis)

    I am trying to access the SO Sales Order header information by setting up an oSO_SOSalesOrderBus object linked to the SO_SalesOrder_Bus data source.  I dont get errors when I do this, however I do not get the Customer number or any of the other data from the SO Header to pull into my variables.  Is it possible to access the SO Header from the SO Details?  

    Thank you,
    Marc


    here is my code snip:

    'get access to header information
    'first get the sales order number of the details here
    retval = oBusObj.getvalue("SalesOrderNo$",sSalesOrderNo)  'Sales order number on SO Details
    oScript.DebugPrint "SalesOrder No stored in Details is " & sSalesOrderNo
    sPaddedSONum = sSalesOrderNo & String(7 - Len(sSalesOrderNo),Chr(0))
    oScript.DebugPrint "Padded SO Number is " & sPaddedSONum

    if isObject(oSO_SOSalesOrderBUS)=false then
       Set oSO_SOSalesOrderBUS = oSession.AsObject(oSession.GetObject("SO_SalesOrder_BUS"))
        oScript.DebugPrint("Instantiate oSO_SOSalesOrderBUS")
    end if


    'now setup key value for SO Header
    retVal1 = oSO_SOSalesOrderBUS.SetKeyValue("SalesOrderNo$",sPaddedSONum)
    retVal2 =oSO_SOSalesOrderBUS.Find()
    oScript.DebugPrint "so header find returns " & Retval2

    if retval2 = 1 then 'so is found!
    retVal =oSO_SOSalesOrderBUS.getvalue("CustomerNo$",sSOHCustomerNo)
    retVal = oSO_SOSalesOrderBus.getvalue("BillToAddress1$",sTempVar)
    oscript.debugprint "Customer number is  " & sSOHCustomerNo
    oScript.DebugPrint "Temp Var is " & sTempVar
    END IF

    'end get access to header info

    ------------------------------
    Marc Cregan
    Technology Integrators
    ------------------------------


  • 2.  RE: Sage 100 Scripting accessing SO Header info from SO Details script

    Posted 04-30-2020 14:56
    Edited by David Speck II 04-30-2020 14:58
    In a UDS attached to a detail/lines object, the oHeaderObj variable should exist and be set to the header object for the current record.
    You can check for its existence using the following.
    If IsObject(oHeaderObj) Then
    	sCustomerNo = "" : oHeaderObj.GetValue "CustomerNo$", sCustomerNo
    	oScript.DebugPrint "sCustomerNo: " & sCustomerNo
    End If​


    Also, if you only need to read info from a header object's fields, use the _Svc version of the object so you don't put records into and edit state and there is less overhead due to the number of inherited object classes between the _Bus and _Svc objects. Just be aware that header _Svc objects DO NOT have a Lines property to read detail/line info.



    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------



  • 3.  RE: Sage 100 Scripting accessing SO Header info from SO Details script

    Posted 04-30-2020 16:46
    Hi David - Thank you this is what I needed - now I can get to the customer record!   I appreciate the assistance!  Marc

    ------------------------------
    Marc Cregan
    Technology Integrators
    ------------------------------



  • 4.  RE: Sage 100 Scripting accessing SO Header info from SO Details script

    Posted 04-30-2020 17:09
    If you need to get to the customer record itself, there might be a shortcut you can use... (untested, but it should work).

    Set oCust = oBusObj.AsObject(oHeaderObj.GetChildHandle("CustomerNo"))



    ------------------------------
    Kevin Moyes
    Technical Systems Analyst
    Munjal White Consulting Co.
    Toronto ON
    ------------------------------



  • 5.  RE: Sage 100 Scripting accessing SO Header info from SO Details script

    Posted 05-01-2020 14:51
    Edited by David Speck II 05-01-2020 14:54
    Good point Kevin, i missed that he was going after the price level from the customer record and was thinking he was just going after info at the header level. Your example should be the option to use.

    Marc, just be aware that you may need to use the following line on a line before Kevin's example to force the child object to be on the correct record.
    oHeaderObj.ReadAdditional "CustomerNo"

    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------