Sales Order To PO Address and lines button script

SOLVED

Hello everyone,

I'm stuck on a problem. I wrote a script to run from a button on the address tab of Purchase Order Entry. I made a field to collect a Sales Order number that the user types in the clicks the button to generate the ship to address from the Sales order onto the Purchase order basically for drop ships. They added on to the request to see if it was possible to also copy all of the line information from the Sales order to the Purchase order. I have the written the below but, it doesn't seem to do anything besides copy the Ship to address from the Sales order to the Purchase order. I can't get it to write the lines or even find the item. Any help with this would be much appreciated.
/resized-image/__size/640x480/__key/communityserver-discussions-components-files/100/SO_5F00_PO.png

oSO = 0
oSO1 = 0
oPO = 0
oLines = 0
retVal = 0
sSO = ""
sPO = ""
sSTName = ""
sSTAddress1=""
sSTAddress2=""
sSTAddress3=""
sSTCity=""
sSTState=""
sSTZipcode=""
sSTCountry=""
sMsg = ""
sLine1 = ""

sSOItem=""
sPOItem=""

retVal = oBusObj.GetValue("UDF_SalesOrder$", sSO)


If sSO <> "" Then
Set oSO = oSession.AsObject(oSession.GetObject("SO_SalesOrder_bus"))
retVal = oSO.SetKeyValue("SalesOrderNo$", sSO)
retval = oSO.Find()

If retVal = 1 Then
retVal = oSO.GetValue("ShipToName$", sSTName)
retVal = oSO.GetValue("ShipToAddress1$", sSTAddress1)
retVal = oSO.GetValue("ShipToAddress2$", sSTAddress2)
retVal = oSO.GetValue("ShipToAddress3$", sSTAddress3)
retVal = oSO.GetValue("ShipToCity$", sSTCity)
retVal = oSO.GetValue("ShipToState$", sSTState)
retVal = oSO.GetValue("ShipToZipCode$", sSTZipcode)
retVal = oSO.GetValue("ShipToCountryCode$", sSTCountry)
End If
retVal = oBusObj.SetValue("ShipToName$", sSTName)
retVal = oBusObj.SetValue("ShipToAddress1$", sSTAddress1)
retVal = oBusObj.SetValue("ShipToAddress2$", sSTAddress2)
retVal = oBusObj.SetValue("ShipToAddress3$", sSTAddress3)
retVal = oBusObj.SetValue("ShipToCity$", sSTCity)
retVal = oBusObj.SetValue("ShipToState$", sSTState)
retVal = oBusObj.SetValue("ShipToZipCode$", sSTZipcode)
retVal = oBusObj.SetValue("ShipToCountryCode$", sSTCountry)

'End IF
'If sSO <> "" Then
Set oSO1 = oSession.AsObject(oSession.GetObject("SO_SalesOrderDetail_bus"))
retVal = oSO1.SetKeyValue("SalesOrderNo$", sSO)
retval = oSO1.Find()
If retVal = 1 Then
do while oSO1.EOF <> 1
'retVal = oSO1.GetValue("LineKey$", sLine1)
retVal = oSO1.GetValue("ItemCode$", sSOItem)
IF sSOItem <> "" then
Set oLines = oSession.AsObject(oBusObj.Lines)
retVal = oLines.MoveFirst()
'retVal = oLines.setValue("LineKey$", sLine1)
retVal = oLines.setValue("ItemCode$", sSOItem)
retVal = oLines.Write()
retVal = oLines.MoveNext()
Else
retVal = oLines.MoveNext()
end if

loop
end if
end if

Parents
  • 0

    Try this to access the SO lines (instead of your oSO1 stuff)... which should work without the SetKeyValue / Find, since you are referencing the lines in relation to oSO (that already has the SO open).

    Set oSOLines = oSession.AsObject(oSO.Lines)

  • +1 in reply to Kevin M
    verified answer

    Thanks Kevin. This helped alot. The final script is below if anyone needed it.

    'Button Script PO Entry Tab 2 Address
    'This script copies ship to information from the sales order entered in the SO field inside of PO Entry
    'This produces will also copy over the line items quantity ordered and comments.
    '11-9-23 DP
    oSO = 0
    oSO1 = 0
    oPO = 0
    oLines = 0
    retVal = 0
    sSO = ""
    sPO = ""
    sSTName = ""
    sSTAddress1=""
    sSTAddress2=""
    sSTAddress3=""
    sSTCity=""
    sSTState=""
    sSTZipcode=""
    sSTCountry=""
    sMsg = ""
    sLine1 = ""
    sSOItem=""
    sPOItem=""
    oSOLines = 0
    retVal = oBusObj.GetValue("UDF_SalesOrder$", sSO)
    nOrdered = 0
    sMsg = ""
    sComment=""

    If sSO <> "" Then
    Set oSO = oSession.AsObject(oSession.GetObject("SO_SalesOrder_bus"))
    retVal = oSO.SetKeyValue("SalesOrderNo$", sSO)
    retVal = oSO.SetKey()
    retval = oSO.Find()

    If retVal = 1 Then
    retVal = oSO.GetValue("ShipToName$", sSTName)
    retVal = oSO.GetValue("ShipToAddress1$", sSTAddress1)
    retVal = oSO.GetValue("ShipToAddress2$", sSTAddress2)
    retVal = oSO.GetValue("ShipToAddress3$", sSTAddress3)
    retVal = oSO.GetValue("ShipToCity$", sSTCity)
    retVal = oSO.GetValue("ShipToState$", sSTState)
    retVal = oSO.GetValue("ShipToZipCode$", sSTZipcode)
    retVal = oSO.GetValue("ShipToCountryCode$", sSTCountry)
    'End If
    retVal = oBusObj.SetValue("ShipToName$", sSTName)
    retVal = oBusObj.SetValue("ShipToAddress1$", sSTAddress1)
    retVal = oBusObj.SetValue("ShipToAddress2$", sSTAddress2)
    retVal = oBusObj.SetValue("ShipToAddress3$", sSTAddress3)
    retVal = oBusObj.SetValue("ShipToCity$", sSTCity)
    retVal = oBusObj.SetValue("ShipToState$", sSTState)
    retVal = oBusObj.SetValue("ShipToZipCode$", sSTZipcode)
    retVal = oBusObj.SetValue("ShipToCountryCode$", sSTCountry)


    Set oSOLines = oSession.AsObject(oSO.Lines)
    'do while oSOLines.EOF <> 1
    retVal = oSOLines.MoveFirst()
    do until oSOLines.EOF

    retVal = oSOLines.GetValue("LineKey$", sLine1)
    retVal = oSOLines.GetValue("ItemCode$", sSOItem)
    retVal = oSOLines.GetValue("QuantityOrdered", nOrdered)
    retVal = oSOLines.GetValue("CommentText$", sComment)
    IF sSOItem <> "" then
    Set oLines = oSession.AsObject(oBusObj.Lines)
    retVal = oLines.MoveFirst()
    retVal = oLines.AddLine()
    retVal = oLines.setValue("LineKey$", sLine1)
    retVal = oLines.setValue("ItemCode$", sSOItem)
    retVal = oLines.setValue("QuantityOrdered", nOrdered)
    retVal = oLines.setValue("CommentText$", sComment)
    retVal = oLines.Write()
    retVal = oLines.MoveNext()
    'retVal = oSOLines.MoveNext()
    'sMsg = "The Sales order is " & sSO& " and the line key is" & sLine1& " and the item is "&sSOItem&" This is message 1"
    retMsg = oSession.AsObject(oSession.UI).MessageBox("", sMsg)
    'Else
    'retVal = oLines.MoveNext()
    'retVal = oSOLines.MoveNext()
    'sMsg = "The Sales order is " & sSO& " and the line key is" & sLine1& " and the item is "&sSOItem& " This is message 2"
    'retMsg = oSession.AsObject(oSession.UI).MessageBox("", sMsg)
    end if
    retVal = oSOLines.MoveNext()

    loop

    end if
    retVal = oSession.DropObject("SO_SalesOrder_bus")
    end if

Reply
  • +1 in reply to Kevin M
    verified answer

    Thanks Kevin. This helped alot. The final script is below if anyone needed it.

    'Button Script PO Entry Tab 2 Address
    'This script copies ship to information from the sales order entered in the SO field inside of PO Entry
    'This produces will also copy over the line items quantity ordered and comments.
    '11-9-23 DP
    oSO = 0
    oSO1 = 0
    oPO = 0
    oLines = 0
    retVal = 0
    sSO = ""
    sPO = ""
    sSTName = ""
    sSTAddress1=""
    sSTAddress2=""
    sSTAddress3=""
    sSTCity=""
    sSTState=""
    sSTZipcode=""
    sSTCountry=""
    sMsg = ""
    sLine1 = ""
    sSOItem=""
    sPOItem=""
    oSOLines = 0
    retVal = oBusObj.GetValue("UDF_SalesOrder$", sSO)
    nOrdered = 0
    sMsg = ""
    sComment=""

    If sSO <> "" Then
    Set oSO = oSession.AsObject(oSession.GetObject("SO_SalesOrder_bus"))
    retVal = oSO.SetKeyValue("SalesOrderNo$", sSO)
    retVal = oSO.SetKey()
    retval = oSO.Find()

    If retVal = 1 Then
    retVal = oSO.GetValue("ShipToName$", sSTName)
    retVal = oSO.GetValue("ShipToAddress1$", sSTAddress1)
    retVal = oSO.GetValue("ShipToAddress2$", sSTAddress2)
    retVal = oSO.GetValue("ShipToAddress3$", sSTAddress3)
    retVal = oSO.GetValue("ShipToCity$", sSTCity)
    retVal = oSO.GetValue("ShipToState$", sSTState)
    retVal = oSO.GetValue("ShipToZipCode$", sSTZipcode)
    retVal = oSO.GetValue("ShipToCountryCode$", sSTCountry)
    'End If
    retVal = oBusObj.SetValue("ShipToName$", sSTName)
    retVal = oBusObj.SetValue("ShipToAddress1$", sSTAddress1)
    retVal = oBusObj.SetValue("ShipToAddress2$", sSTAddress2)
    retVal = oBusObj.SetValue("ShipToAddress3$", sSTAddress3)
    retVal = oBusObj.SetValue("ShipToCity$", sSTCity)
    retVal = oBusObj.SetValue("ShipToState$", sSTState)
    retVal = oBusObj.SetValue("ShipToZipCode$", sSTZipcode)
    retVal = oBusObj.SetValue("ShipToCountryCode$", sSTCountry)


    Set oSOLines = oSession.AsObject(oSO.Lines)
    'do while oSOLines.EOF <> 1
    retVal = oSOLines.MoveFirst()
    do until oSOLines.EOF

    retVal = oSOLines.GetValue("LineKey$", sLine1)
    retVal = oSOLines.GetValue("ItemCode$", sSOItem)
    retVal = oSOLines.GetValue("QuantityOrdered", nOrdered)
    retVal = oSOLines.GetValue("CommentText$", sComment)
    IF sSOItem <> "" then
    Set oLines = oSession.AsObject(oBusObj.Lines)
    retVal = oLines.MoveFirst()
    retVal = oLines.AddLine()
    retVal = oLines.setValue("LineKey$", sLine1)
    retVal = oLines.setValue("ItemCode$", sSOItem)
    retVal = oLines.setValue("QuantityOrdered", nOrdered)
    retVal = oLines.setValue("CommentText$", sComment)
    retVal = oLines.Write()
    retVal = oLines.MoveNext()
    'retVal = oSOLines.MoveNext()
    'sMsg = "The Sales order is " & sSO& " and the line key is" & sLine1& " and the item is "&sSOItem&" This is message 1"
    retMsg = oSession.AsObject(oSession.UI).MessageBox("", sMsg)
    'Else
    'retVal = oLines.MoveNext()
    'retVal = oSOLines.MoveNext()
    'sMsg = "The Sales order is " & sSO& " and the line key is" & sLine1& " and the item is "&sSOItem& " This is message 2"
    'retMsg = oSession.AsObject(oSession.UI).MessageBox("", sMsg)
    end if
    retVal = oSOLines.MoveNext()

    loop

    end if
    retVal = oSession.DropObject("SO_SalesOrder_bus")
    end if

Children
No Data