Code For Sales Order CRUD Using Business Object

This BOI is driving me nuts. You just cant tell why something is not working. Would someone be willing to post full code examples for Sales Order CRUD Operations?

What I need to do is:

  1. Create the original Sales Order
  2. Update the Sales Order
  3. Add line Items
  4. Update line Items
  5. Delete line Items

VB or C#

*I think this would be very helpful not only to me but to the rest of the community as well.

As a follow up, clear, concise and commented code to make a proper connection, create the instance and destroy the instance would be helpful to all as well.

  • 0

    My examples from "100E - Sage 100 ERP - Object Interface Course" cover this list.

    If you've taken this course then you should be able to do these things.  

    I think it's an excellent idea for you to post your documented examples for the rest of the community.

  • 0 in reply to BadgerJerry

    Thank you Jerry. I'm afraid I have been through it several times. Managed to get connected, created the object, created the sales order. But now using the same methods I cannot get it to simply update and not sure what i am doing wrong. Here is my function. Note, The first two calls to create the connection and create the object have been working to both create and read the through the list of sales orders.

       Public Function AddItemsToSalesOrder(ByVal son As String) As Boolean

           Try

               CreateMASConnection()

               CreateSalesOrderObj()

               oSO_Object.nSetKeyValue("SalesOrderNo$", son)

               oSO_Object.nSetKey()

               'retVAL = oSO_Object.nSetKey(sOrderNo)

               rtnVal = oSO_Object.oLines.nAddLine()  'Insert a new line

               rtnVal = oSO_Object.oLines.nSetValue("ItemCode$", "CUSTOM BIG BOX") 'Set the value of the ItemCode

               rtnVal = oSO_Object.oLines.nSetValue("WarehouseCode", "010") 'Only needs to be set if different than the Hdr warehouse

               rtnVal = oSO_Object.oLines.nSetValue("QuantityOrdered", 3)

               rtnVal = oSO_Object.oLines.nSetValue("UnitPrice", 9999.0)

               rtnVal = oSO_Object.oLines.nSetValue("CommentText$", "This is a inline comment 222.") 'String fields need to be suffixed with a $

               rtnVal = oSO_Object.oLines.nWrite() 'This writes the line to memory. Once Header is written below both are physically written to disk

               oSO_Object.nWrite()

               DestroySOObject()

               Return True

           Catch ex As Exception

               Return False

           End Try

       End Function

       Public Function CreateMASConnection() As Boolean

           'Get the MAS Home directory

           sPathHome = "COMMENTED OUT FOR THIS POST"

           'Create ProvideX COM Object

           oScript = CreateObject("ProvideX.Script")

           'Run Init method of COM object

           oScript.Init(sPathHome)

           'Create Session Object

           oSession = oScript.NewObject("SY_Session")

           ' SetUser Method

           rtnUsertnVal = oSession.nSetUser("NAME", "PASSWORD")  'put your UserID and password here

           If rtnUsertnVal = 0 Then

               sLastErrortnVal = oSession.sLastErrorMsg

               sMsg = "Oops could not login to MAS." & vbCrLf & _

                 "Last Error: " & sLastErrorMsg & vbCrLf & _

                 "Program exiting .."

               MsgBox("CreateMASConnection: " + sMsg)

               Return False

           End If

           Return True

       End Function

       Public Function CreateSalesOrderObj() As Boolean ' This Process Takes A Long Time

           ' Create the security handle

           oSecurity = oSession.nSetProgram(oSession.nLookupTask("SO_SalesOrder_UI"))

           If oSO_Object Is Nothing Then

               oSO_Object = oScript.NewObject("SO_SalesOrder_bus", oSession)

           End If

           If oSO_Object Is Nothing Then

               sMsg = "ERROR: Cannot Connect To Sales Order Group"

               MsgBox(sMsg)

               Return False

           End If

           Return True

       End Function

  • 0 in reply to John1966

    where does it fail?  are you checking each rtnVal?

    if you put a rtnVal in front of oSO_Object.nWrite() what's the value?

    also what's the value of oSO_Object.sLastErrorMsg and oSO_Object.oLines.sLastErrorMsg?

  • 0 in reply to BadgerJerry

    Adding in the check i get 1s for

               rtnVal = oSO_Object.nSetKeyValue("SalesOrderNo$", son)

               rtnVal = oSO_Object.nSetKey()

    I get a 2 for

    rtnVal = oSO_Object.oLines.nAddLine()

    I get my first 0 here : Last Error Message =  Module R/A is not on file

    rtnVal = oSO_Object.oLines.nSetValue("ItemCode$", "CUSTOM BIG BOX")

    Changed Function Below For Others To View:

    Public Function AddItemsToSalesOrder(ByVal son As String) As Boolean

           Dim sLastErrorMsg As String = ""

           Try

               CreateMASConnection()

               CreateSalesOrderObj()

               rtnVal = oSO_Object.nSetKeyValue("SalesOrderNo$", son)

               rtnVal = oSO_Object.nSetKey()

               'retVAL = oSO_Object.nSetKey(sOrderNo)

               rtnVal = oSO_Object.oLines.nAddLine()  'Insert a new line

               If rtnVal = 0 Then

                   sLastErrortnVal = oSession.sLastErrorMsg

                   sMsg = sLastErrorMsg & vbCrLf

                   MsgBox(sMsg)

               End If

               rtnVal = oSO_Object.oLines.nSetValue("ItemCode$", "CUSTOM BIG BOX") 'Set the value of the ItemCode

               If rtnVal = 0 Then

                   sLastErrortnVal = oSession.sLastErrorMsg

                   sMsg = sLastErrortnVal.ToString()

                   MsgBox(sMsg)

               End If

               rtnVal = oSO_Object.oLines.nSetValue("WarehouseCode", "010") 'Only needs to be set if different than the Hdr warehouse

               If rtnVal = 0 Then

                   sLastErrortnVal = oSession.sLastErrorMsg

                   sMsg = sLastErrortnVal.ToString()

                   MsgBox(sMsg)

               End If

               rtnVal = oSO_Object.oLines.nSetValue("QuantityOrdered", 3)

               If rtnVal = 0 Then

                   sLastErrortnVal = oSession.sLastErrorMsg

                   sMsg = sLastErrortnVal.ToString()

                   MsgBox(sMsg)

               End If

               rtnVal = oSO_Object.oLines.nSetValue("UnitPrice", 9999.0)

               If rtnVal = 0 Then

                   sLastErrortnVal = oSession.sLastErrorMsg

                   sMsg = sLastErrortnVal.ToString()

                   MsgBox(sMsg)

               End If

               rtnVal = oSO_Object.oLines.nSetValue("CommentText$", "This is a inline comment 222.") 'String fields need to be suffixed with a $

               If rtnVal = 0 Then

                   sLastErrortnVal = oSession.sLastErrorMsg

                   sMsg = sLastErrortnVal.ToString()

                   MsgBox(sMsg)

               End If

               rtnVal = oSO_Object.oLines.nWrite() 'This writes the line to memory. Once Header is written below both are physically written to disk

               If rtnVal = 0 Then

                   sLastErrortnVal = oSession.sLastErrorMsg

                   sMsg = sLastErrortnVal.ToString()

                   MsgBox(sMsg)

               End If

               rtnVal = oSO_Object.nWrite()

               If rtnVal = 0 Then

                   sLastErrortnVal = oSession.sLastErrorMsg

                   sMsg = sLastErrortnVal.ToString()

                   MsgBox(sMsg)

               End If

               DestroySOObject()

               Return True

           Catch ex As Exception

               Return False

           End Try

       End Function

  • 0 in reply to John1966

    Im using the wrong error message as well as a try catch which does nothing for me except preventing the program from going down.

    oSO_Object.sLastErrorMsg is saying the record is open by someone else and oSO_Object.oLines.sLastErrorMsg is saying that "CUSTOM BIG BOX" does not exist.

    Thank you for the slap in the back of the head Jerry...LOL..I think I am just losing my patience with this thing.

  • 0 in reply to John1966

    Happy to give you the "slap in the back of the head" that you needed.

    Make sure to pay it forward.  Too many on this board ask more questions than they answer.