Sage 100

 View Only
  • 1.  Concept for Reverse Unit Price Calculation

    Posted 05-18-2020 16:23
    ​I have been fighting with this for a few days and cannot seem to figure out the appropriate concept/events to use for what I am trying to achieve. I created an initial script for the client that calculates a SO Line Gross Profit % UDF based on custom price and cost fields, and that works fine as PostValidate on Qty Ordered/Unit Price. Then they came back and asked that if there are changes made to the GPM% field that the Unit Price field should be recalculated. My draft appears to work fine for many items, but for some items, the recalc will change the Unit Price by a cent or so based on rounding (i.e. no changes are manually made to either the Unit Price or GPM, but I have no conditional clauses in yet so both scripts run and can cause the Unit Price to change slightly depending on the GPM%). I would like to try to figure out how to trigger the reverse recalc script only on change to the GPM% UDF. I've been testing stored variables and pre-validate/prewrite events to see if I can capture the "original" GPM for comparison but all that happens is that I get thrown into a small loop of the two scripts wanting to keep recalculating each other. Hopefully this question is easy enough to visualize. Any suggestions would be welcome. Thanks in advance! #scripting

    ------------------------------
    Amber Prayfrock, Blytheco
    ------------------------------


  • 2.  RE: Concept for Reverse Unit Price Calculation

    Posted 05-18-2020 18:50
    Are you making use of the oScript.DeactivateProcedure and oScript.ActivateProcedure methods?
    Here are examples of what to pass to the method.
    • "PreWrite"
    • "PostWrite"
    • "PreValidation_QuantityOrdered"
    • "PostValidation_UnitPrice"
    • "*" (This is supposed to only affect the current procedure event, i.e, if the script was triggered on the pre-validate of quantity ordered, then this would be the same as passing  "PreValidation_QuantityOrdered" to it.)
    • "*ALL* (This is supposed to affect all procedure events for the current object that oScript handles. So if running in a script attached to the detail, passing "*ALL*" will affect all scripts attached to the detail table but will not affect scripts attached to the header table. To affect the header scripts from the detail script, you can do something like this.
      • If IsObject(oHeaderObj) Then
        	If oHeaderObj.ScriptObject > 0 Then
        		oSession.AsObject(oHeaderObj.ScriptObject).DeactivateProcedure "*ALL*"
        	End If
        End If
        
        ' Do stuff here.
        
        If IsObject(oHeaderObj) Then
        	If oHeaderObj.ScriptObject > 0 Then
        		oSession.AsObject(oHeaderObj.ScriptObject).ActivateProcedure "*ALL*"
        	End If
        End If


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



  • 3.  RE: Concept for Reverse Unit Price Calculation

    Posted 05-20-2020 15:08
    David, as always, I appreciate your guidance and willingness to help. I am researching some examples on how to use these functions with what I have going, but I'm glad to know there is some kind of "container" we can put around Set Values.

    ------------------------------
    Amber Prayfrock, Blytheco
    ------------------------------