PO Receipt Detail

Getting stuck on this script, I've tried a column post val on the qty received and a table post read.  Both are getting stuck at the same point, on the first "retVal=oSOLines.MoveNext()", should it be MoveFirst?

Dim sPurchaseOrderNo
Dim sSalesOrderNo
Dim sItemCode
Dim sItemCodeCur
Dim nPO_QTYREC
Dim nSO_QTYREC
Dim sOrderStatus
Dim oSalesOrder

sPurchaseOrderNo = ""
sSalesOrderNo = ""
sItemCode = ""
sItemCodeCur = ""
nPO_QTYREC = 0
nSO_QTYREC = 0
nSOPREVREC = 0
nNEWSO_QTYREC = 0
sOrderStatus = ""
oSalesOrder = 0

retVal = oBusObj.GetValue("SalesOrderNo$",sSalesOrderNo)
r=oScript.DebugPrint("SalesOrderNo: " & sSalesOrderNo)


if sSalesOrderNo <> "" then

	retVal = oBusObj.GetValue("ItemCode$",sItemCode)
	retVal = oBusObj.GetValue("QuantityReceived",nPO_QTYREC)
	r=oScript.DebugPrint("ItemCode: " & sItemCode)
	r=oScript.DebugPrint("Quantity Rec: " & CStr(nPO_QTYREC))
	
	If nPO_QTYREC <> 0 Then
	
		oSOLines = oSession.GetObject("SO_SalesOrderDetail_bus")
		r=oScript.DebugPrint("After oSession.GetObj ")


		If oSOLines <> 0 Then
			SET oSOLines = oSession.AsObject(oSOLines)
			r=oScript.DebugPrint("After Set oSession.AsObj ")
			sSONo = ""
			

			retVal = oSOLines.SetBrowseFilter(sSalesOrderNo)
			r=oScript.DebugPrint("retVal SO Line SetBrowseFilter = " & CStr(retVal))
			retVal = oSOLines.MoveNext()
			r=oScript.DebugPrint("retVal SO Line MoveNext = " & CStr(retVal))
			retVal = oSOLines.GetValue("SalesOrderNo$", sSONo )
			r=oScript.DebugPrint("SO No: " & sSONo)
			r=oScript.DebugPrint("oSOLines BOF: " & cBool(oSOLines.BOF))
			r=oScript.DebugPrint("oSOLines EOF: " & cBool(oSOLines.EOF))
			
				
			sItem = "" : sComment = "" : sLineKey = "" : sItemType = "" : sItemDesc = ""
			nRevQty = 0 : nLUPrice = 0 : nLExtAmt = 0
			
			
			'Now Loop through the lines looking for any item codes beginning with a /
			lineUpdated = 0 ' initialize new indicator

			Do While Not CBool(oSOLines.EOF) And lineUpdated = 0
				retVal = oSOLines.GetValue("ItemCode$",sItemCodeCur)
																						
				if sItemCode = sItemCodeCur AND (sOrderStatus = "N" Or sOrderStatus ="O") Then

					retVal = oSOLines.GetValue("UDF_QTY_RECEIVED", nSOPREVREC)
					nNEWSO_QTYREC = nSOPREVREC+nSO_QTYREC
					retVal = oSOLines.SetValue("UDF_QTY_RECEIVED",nNEWSO_QTYREC)
					retVal = oSOLines.Write()
					lineUpdated = 1 'trip flag
										
				end if
				retVal = oSOLines.MoveNext()
				r=oScript.DebugPrint("SO Line ItemCode = " & sItemCode)
				
				
				retVal = oSOLines.GetValue("SalesOrderNo$", sSONo )
				r=oScript.DebugPrint("Lines SONo  = " & sSONo)

			Loop
		End If 'Check to see that we can open SO_SalesOrderHistoryHeader

Parents
  • 0

    Two questions, wouldn’t the event trigger being triggered again not be a bad thing?  If the quantity received is updated then the SO is updated.

    I’m not sure how you do from a header to the lines, the oSession syntax loses me.

    I tried a version of This script I had originally used but it gets caught looping the SO I think, doesn’t update the lines.  And I can’t figure out how to incorporate parts of that script to this one.  I’ll reply with the first script I started with.

  • 0 in reply to jland47

    Trigger the event from the same receipt multiple times, and the quantity added to the SO would be greater than it should be.

    That linked script has the objects handled correctly... create the SO header object, open the record, then create the oSOLines object from the .Lines property of the SO header object.

    oSalesOrder = oSession.GetObject("SO_SalesOrder_bus")
    if oSalesOrder <> 0 then
        Set oSalesOrder = oSession.AsObject(oSalesOrder)
    else 
        ' you probably want to handle this, if the SO object can't be opened.
    end if
    retVal = oSalesOrder.SetKeyValue("SalesOrderNo$", sSalesOrderNo)
    retVal = oSalesOrder.SetKey()
    if retVal = 1 then
        ...
        Set oSOLine = oSession.AsObject(oSalesOrder.Lines)
        retVal = oSOLine.MoveFirst()
        ...

  • 0 in reply to Kevin M

    OK, been watching script closely and it works most of the time.  However, I have a couple po's where it doesn't write anything back to any of the sales orders, I can't pin point why some receipts work and some don't.  Added a udf to be able to match which SO line "gets" the qty received in case the same item is on one SO multiple times, not sure if that is throwing a bug in it?

    Dim sPurchaseOrderNo
    Dim sSalesOrderNo
    Dim sItemCode
    Dim sItemCodeCur
    Dim nPO_QTYREC
    Dim nSO_QTYREC
    Dim sOrderStatus
    Dim oSalesOrder
    
    sPurchaseOrderNo = ""
    sSalesOrderNo = ""
    sItemCode = ""
    sItemCodeCur = ""
    nPO_QTYREC = 0
    nSO_QTYREC = 0
    nSOPREVREC = 0
    nNEWSO_QTYREC = 0
    sOrderStatus = ""
    sPOSOLines = ""
    oSalesOrder = 0
    
    retVal = oBusObj.GetValue("SalesOrderNo$",sSalesOrderNo)
    r=oScript.DebugPrint("SalesOrderNo: " & sSalesOrderNo)
    
    
    if sSalesOrderNo <> ""  then
    
    
    	retVal = oBusObj.GetValue("ItemCode$",sItemCode)
    	retVal = oBusObj.GetValue("QuantityReceived",nPO_QTYREC)
    	retVal = oBusObj.GetValue("UDF_SOLINES$",sPOSOLines)
    
    	r=oScript.DebugPrint("ItemCode: " & sItemCode)
    	r=oScript.DebugPrint("Quantity Rec: " & CStr(nPO_QTYREC))
    	
    	If nPO_QTYREC <> 0 Then
    	
    		nSO_QTYREC = nPO_QTYREC
    
    		oSalesOrder = oSession.GetObject("SO_SalesOrder_bus")
    		r=oScript.DebugPrint("After oSession.GetObj")
    
    		if oSalesOrder <> 0 then
    
    			Set oSalesOrder = oSession.AsObject(oSalesOrder)
    			r=oScript.DebugPrint("After AsObject for oSalesOrder")
    
    			retVal = oSalesOrder.SetKeyValue("SalesOrderNo$", sSalesOrderNo)
    			retVal = oSalesOrder.SetKey()
    
    			if retVal = 1 Then
    			
    				r=oScript.DebugPrint("After Successful SO SetKey ")
    
    				retVal = oSalesOrder.GetValue("OrderStatus$",sOrderStatus)
    				r=oScript.DebugPrint("OrderStatus: " & sOrderStatus)
    
    	
    				Set oSOLine = oSalesOrder.AsObject(oSalesOrder.Lines)
    '				retVal = oSOLine.SetKeyValue("SalesOrderNo$", sSalesOrderNo)
    '				retVal = oSOLine.SetKeyValue("LineKey$", sSOLines)
    '				retVal = oSOLine.SetKey()
    
    				r=oScript.DebugPrint("After AsObject oSOLines ")
    
    				retVal = oSOLine.MoveFirst()
    				r=oScript.DebugPrint("After MoveFirst ")
    				sLineSONo=""
    				sSOLinesKey = ""
    				retVal = oSOLine.GetValue("SalesOrderNo$",sLineSONo)
    				r=oScript.DebugPrint("Lines SO Num " & sLineSONo)
    
    
    				lineUpdated = 0 ' initialize new indicator
    
    				do until (oSOLine.Eof or lineUpdated=1)
    
    					retVal = oSOLine.GetValue("ItemCode$",sItemCodeCur)
    					retVal = oSOLine.GetValue("LineKey$",sSOLinesKey)
    					r=oScript.DebugPrint("CurrentItemCode: " & sItemCodeCur)
    					r=oScript.DebugPrint("CurrentItemCode: " & sItemCodeCur)
    																							
    					if sItemCode = sItemCodeCur AND (sOrderStatus = "N" Or sOrderStatus ="O") And sSOLinesKey = sPOSOLines Then
    
    						retVal = oSOLine.GetValue("UDF_QTY_RECEIVED", nSOPREVREC)
    						nNEWSO_QTYREC = nSOPREVREC+nSO_QTYREC
    						retVal = oSOLine.SetValue("UDF_QTY_RECEIVED",nNEWSO_QTYREC)
    						retVal = oSOLine.Write()
    						lineUpdated = 1 'trip flag
    						r=oScript.DebugPrint("retVal on oSOLine Write: " & CStr(retVal))
    						r=oScript.DebugPrint("lineUpdated = " & CStr(lineUpdated))
    											
    					end if
    					retVal = oSOLine.MoveNext()
    				loop
    							
    				if lineUpdated=1 then ' only write if we found a match
    								
    					retVal = oSalesOrder.Write()
    					r=oScript.DebugPrint("retVal on oSalesOrder Write: " & CStr(retVal))
    
    				end if
    
    				retVal = oSOLine.MoveNext()									
    						
    			end If
    		End If
    	end if
    
    end if

  • 0 in reply to jland47

    Check if the SO is locked from edits (which happens when someone has it open in SO Entry, or if there is an unposted invoice for that SO... or Credit Hold can block things too depending on permissions).

  • 0 in reply to Kevin M

    The permissions are determined by the user that is firing off the script?

  • 0 in reply to jland47

    Yes, that is correct.

Reply Children
  • 0 in reply to Kevin M

    I have pretty much full access to everything except PR information, everything on the SO's look normal.  The other odd issue is the script seems to get hung up on some SO's as well, states the user (me) has the SO locked and I can not unlock it unless I close the receipt of goods screen.