Qty Ordered in SO Entry Script rounding to 2 digits

SOLVED

I have a script that is triggered by a button on the Lines tab of Sales Order entry. I would like to type in the Extension Amount ("Labor $ Sold) and then trigger a script that uses a preset labor rate (in the script) to calculate the qty of labor hours sold. Equation is simply 

Qty = ExtAmt / Lab Rate

Which works fine except that when the Qty value is transferred back to the SO, it is being rounded to 2 decimal places instead of 3, which then throws off the ExtAmt. 

I have made it better by using Round on the Qty equation

Qty = Round(ExtAmt / Lab Rate, 2)  

But I really need the 3rd decimal place to make it work. 

Also, I have checked and Qty Entries in common information is set to 3 decimal places. 

Any ideas 

  • 0
    SUGGESTED
    See module Common Information/Setup/Common Information Options/Quantity Entries.
  • 0 in reply to connex
    Thank you, but as I said above, I checked this and it is set to 3 decimal places.
  • 0 in reply to mlw18064
    I see that now. On what event is your script triggered and can you post the actual script?
  • 0 in reply to connex
    Script is triggered by a button defined with "External Link Definition" on the "Customize: SO_SALESORDER.M4L-PLINES" UI.

    Code is as follows

    dim qty
    qty = 0
    qty = Round(SO_SalesOrderDetail_bus_ExtensionAmt/75,2)
    SO_SalesOrderDetail_bus_UnitPrice = Round(SO_SalesOrderDetail_bus_ExtensionAmt / qty,2)
    SO_SalesOrderDetail_bus_QuantityOrdered = qty



    Example I'm using is ExtAmt = 526.00
    qty should calc to 7.0133
    price should caclulate to 75.00
    ExtAmt should be 526.00

    What I get w/o the Round statements is
    qty = 7.01
    price = 75.00
    ExtAmt = 525.75,

    What I get with the Round statements is
    qty = 7.01
    price = 75.04
    ExtAmt = 526.03,
  • 0 in reply to mlw18064

    Can you explain what you mean by "Example I'm using is ExtAmt = 526.00"? The only line type where one can set an Extension Amount is the Miscellaneous Charge type and that type ignores sets to the UnitPrice and QtyOrdered. The other types, Item and Miscellaneous Item Code do not allow a change to the Extended Amount. If you are using a Miscellaneous Charge then I think you will need to setup UDF's for UnitPrice and QtyOrdered.

  • 0 in reply to connex
    Thank you for responding. Yes I am using a Misc Item Code. My attempt was to enter the Extension Amount with price and qty set to zero, then run a script that would fill in the qty and price.

    The script is nearly doing that now except that with Misc Item the ExtAmt is reset to Qty * Price. Since the Qty field is rounded, the ExtAmt is different that what was originally set. If I could maintain 3 decimal places for qty, ExtAmt would calculate correctly, I believe.
  • 0 in reply to mlw18064
    SUGGESTED

    ExtensionAmt is "Read-Only" for Misc Items. It is only "Read-Write" for Misc Charges. I believe a better approach is to use Misc Charges and add UDF_LABOR_RATE and UDF_LABOR_HOURS to the Sales Order Lines table and modify the Crystal form(s) to use those values for your Misc Items instead of the normal QuantityOrdered and UnitPrice.


    Better Still, instead of using a button script (assuming your version is at least 4.40) you could have an event script to calculate at least one multiplicand if not both.

  • 0 in reply to connex
    Thank you. I'll have to give that some thought because it would change other procedures and data reporting.
  • 0

    You could try a conversion function, such as CDbl(ExtAmt / Lab Rate) to force the decimal format.

  • 0 in reply to hyanaga
    verified answer
    CDb gives me a Type Mismatch.

    I can return qty into a UDF and it gives me a full 17 decimal places, so its not the code. For some reason when returning SO_SalesOrderDetail_bus_QuantityOrdered, MAS is truncating it to 2 decimal places. I assume this is something hard coded into MAS and cannot be changed.

    I will consider this closed and look for another option, perhaps the Misc Charge code mentioned above.