automating "Recalc Price" button in S/O entry

4.40 sp 6.0

My client would like to keep SO item pricing up to date for orders/sales to a related company.  Is there a way to automate the price update process associated with the "Recalc Price" button in S/O entry?  

 

I was planning to loop through open order, check the customer number, then update the prices if appropriate.

 

Any ideas?

  • Brian,

     

    The Recalc Price button in sales order entry uses PriceRecalculation() method in the SO_SalesOrder_bus object.   You can do the same.

     

  • Worked perfectly.

     

    Thanks so much,

  • in reply to brc
    I have a client that would like this to execute when creating an order from a Repeating Order. Can I please get more information on how to use PriceRecalculation() method for Sage 100?
  • in reply to MJZ

    MJZ,

    Use a script set to run on the "Pre-Totals" and/or the "Pre-Write" event of the SO Sales Order Header table.

    Use the following to get the value of the source order,

    sSource = ""
    retval = oSession.AsObject(oScript.UIObj).GetValue("ML_CopyFromNo$", sSource)

    Then check if it the source order is a repeating order, if it is then use the following to perform the recalculation.

    retval = oBusObj.PriceRecalculation() 

    Reply back if you have any more questions or need more help.

    EDIT: See my next post

  • in reply to MJZ

    MJZ,

    Had some time to kill, so here is a script that will do what you need.

    It has comments throughout it so you know what is happening and why.

    If you're on version 2015 on greater, you can also set this script to run on the "Post Load" event of the "Lines" and "LinesW" panels. If not, just set it to run on the "Pre Totals" and/or "Pre Write" event/s

    ' Declare and set variable types.
    Dim sSource : sSource = ""
    Dim sCurrentSalesOrderNo : sCurrentSalesOrderNo = ""
    Dim sStoredSalesOrderNo : sStoredSalesOrderNo = ""
    Dim bRecalcTriggered : bRecalcTriggered = 0
    Dim nSO_Svc : nSO_Svc = 0
    Dim oSO_Svc
    Dim sOrderType : sOrderType = ""
    Dim sCopyFromSvc : sCopyFromSvc = ""
    Dim nRetval : nRetval = 0
    Dim sRetval : nRetval = ""
    Dim retval
    Dim sSetKeysValues : sSetKeysValues = ""
    Dim sVersion : sVersion = ""
    Dim nVersion : nVersion = 0
    
    ' Start checking routine.
    ' Make sure this is running under the Sales Order Entry UI task.
    If oSession.StartProgram = "SO_SALESORDER_UI" And _
    	CBool(oScript.UIObj) And _
    	oSession.AsObject(oSession.Security).TaskType = "M" Then
    	' Get the value from the "Copy From" panel and "Copy From Field", if it is blank, do nothing.
    	retval = oSession.AsObject(oScript.UIObj).GetValue("ML_CopyFromNo$", sSource)
    	If sSource <> "" Then 
    		retval = oBusObj.GetValue("SalesOrderNo$", sCurrentSalesOrderNo)
    		retval = oSession.AsObject(oSession.ScriptObject).GetStorageVar("sSalesOrderNo", sStoredSalesOrderNo)
    		retval = oSession.AsObject(oSession.ScriptObject).GetStorageVar("bRecalcTriggered", bRecalcTriggered)
    		' Check if this has already been triggered for this order in this session, if it has then do nothing.
    		If bRecalcTriggered = 0 Or sCurrentSalesOrderNo <> sStoredSalesOrderNo Then 
    			sCopyFromSvc = ""
    			' Find out what data source this is being copied from.
    			retval = oSession.AsObject(oScript.UIObj).GetValue("DB_CopyFrom$", sCopyFromSvc)
    			' Based on data source, set the correct svc object and set key values, the invoice history requires setting the invoice no and header sequence no.
    			Select Case sCopyFromSvc
    				Case "Sales Order"
    				sCopyFromSvc = "SO_SalesOrder_Svc"
    				sSetKeysValues = "retval = oSO_Svc.SetKeyValue(""SalesOrderNo"", """ & sSource & """)"
    				Case "Sales Order/Quote History"
    				sCopyFromSvc = "SO_SalesOrderHistory_Svc"
    				sSetKeysValues = "retval = oSO_Svc.SetKeyValue(""SalesOrderNo"", """ & sSource & """)"
    				Case "Invoice History"
    				sCopyFromSvc = "AR_InvoiceHistoryInquiry_svc"
    				sSetKeysValues = "retval = oSO_Svc.SetKeyValue(""InvoiceNo"", """ & sSource & """) : retval = oSO_Svc.SetKeyValue(""HeaderSeqNo"", ""000000"")"
    			End Select
    			' Get the numeric handle to the svc object.
    			nSO_Svc = oSession.GetObject(sCopyFromSvc)
    			' Set it as an object.
    			Set oSO_Svc = oSession.AsObject(nSO_Svc)
    			' Perform the correct SetKeyValue methods based on above.
    			Execute sSetKeysValues
    			' Use the Find method of svc object to locate the record.
    			nRetval = oSO_Svc.Find()
    			' Check the returned value of the Find method, if the record was found successfully, nRetval will equal 1 and the script will proceed.
    			If nRetval = 1 Then
    				' Get the value of the source order's Order Type.
    				retval = oSO_Svc.GetValue("OrderType$", sOrderType)
    				' If it is equal to "R" for "Repeating Order", then proceed.
    				If sOrderType = "R" Then
    					' Perform the Price Recalculation.
    					retval = oBusObj.PriceRecalculation()
    					' UI Event scripts and the method "GetCurrentProcedure" are only available on version 5.2 (version 2015) or higher so 
    					' everything else in this "IF" block is based on whether your system version meets that criteria.
    					'
    					' This allows you to set this same script to fire on the "Post Load" event of the "Lines" and "LinesW" panel as well as
    					' having it fire on the "Pre Totals" and/or "Pre Write" events of the SO Sales Order Header table.
    					retval = oSession.GetParameter("SYS", "Version$", sVersion)
    					sVersion = Left(sVersion, InStrRev(sVersion, ".") - 1)
    					sVersion = Left(sVersion, InStrRev(sVersion, ".") - 1)
    					nVersion = CDbl(sVersion)
    					If nVersion >= 5.2 Then
    						' Check if we're running on either the PostloadPLINES or PostloadPLINESW event
    						If InStr(oScript.GetCurrentProcedure(), "PostloadPLINES") Then
    							' Perform the PostLoad of the lines tab to force it to reload the lines grid so the user will see the updated values 
    							' without having to switch off and back to the lines tab.
    							Execute "retval = oSession.AsObject(oScript.UIObj)." & oScript.GetCurrentProcedure() & "()"
    						End If
    					End If
    				End If
    			End If
    			' Drop the svc object the script used by referencing the numeric handle.
    			oSession.DropObject(nSO_Svc)
    			' Set the object variable to nothing.
    			Set oSO_Svc = Nothing
    			' Set the session variables so the script knows if the price racalculation has been performed for this order already.
    			retval = oSession.AsObject(oSession.ScriptObject).SetStorageVar("bRecalcTriggered", 1)
    			retval = oSession.AsObject(oSession.ScriptObject).SetStorageVar("sSalesOrderNo", sCurrentSalesOrderNo)
    		End If
    	End If
    End If
    
  • in reply to David Speck
    Thank you so very much!!! Happy New Year