Scripting

Expand all | Collapse all

Scripting We have a script at a client where we

David Overholt

David Overholt08-11-2016 09:37

  • 1.  Scripting We have a script at a client where we

    Posted 08-10-2016 09:43
      |   view attached
    Scripting We have a script at a client where we are currently using ObusObj.SetValueNoValidate to assign a value to the freight field on the sales order header. we are using the ""NoValidate"" option because we get an object not found error if we use ""SetValue"". problem is sometimes the freight is not rounded if we use NoValidate.the really odd thing is that we use ""SetValue"" later in the same script and that processes without error. Can anyone look at this code and tell me if we are just missing something obvious? I can't figure out why the same command would error on one line in the script and work fine on a different line. The text of the code is below but if you look at the screenshot that I've attached, you will see which line errors and which one works. myTaxableAmt = 0 myNonTaxableAmt = 0 myTotalInvoice = 0 myDiscountAmt =0 myFreeFreight = """" myUseCustUpsAccount = """" myRetVal = oBusObj.GetValue(""UDF_FREE_FREIGHT$"",myFreeFreight) myRetVal = oBusObj.GetValue(""UDF_USE_CUST_UPS_ACCOUNT$"",myUseCustUpsAccount) IF myFreeFreight <> ""Y"" THEN IF myUseCustUpsAccount <> ""Y"" THEN myFreightAmt = Value myFreightAmt = ROUND(myFreightAmt,2) myRetVal = oBusObj.GetValue(""PaymentType$"",myPaymentType) myRetVal = oBusObj.GetValue(""TaxableAmt"",myTaxableAmt) myRetVal = oBusObj.GetValue(""NonTaxableAmt"",myNonTaxableAmt) myRetVal = oBusObj.GetValue(""DiscountAmt"",myDiscountAmt) myTotalInvoice = myTaxableAmt + myNonTaxableAmt - myDiscountAmt IF myPaymentType = ""AMEX"" THEN myNewFreightAmt = ROUND((myTotalInvoice * .02) + myFreightAmt,2) myRetVal = oBusObj.SetValueNoValidate(""FreightAmt"", myNewFreightAmt) ELSEIF myPaymentType = ""DISC"" THEN myNewFreightAmt = ROUND((myTotalInvoice * .02) + myFreightAmt,2) myRetVal = oBusObj.SetValueNoValidate(""FreightAmt"", myNewFreightAmt) ELSEIF myPaymentType = ""MC"" THEN 'myNewFreightAmt = (myTotalInvoice * .02) + myFreightAmt myNewFreightAmt = ROUND((myTotalInvoice * .02) + myFreightAmt,2) myRetVal = oBusObj.SetValueNoValidate(""FreightAmt"", myNewFreightAmt) 'myRetVal = oBusObj.SetValue(""FreightAmt"", myNewFreightAmt) ELSEIF myPaymentType = ""VISA"" THEN myNewFreightAmt = ROUND((myTotalInvoice * .02) + myFreightAmt,2) myRetVal = oBusObj.SetValueNoValidate(""FreightAmt"", myNewFreightAmt) Else'Do nothing myRetVal = oBusObj.SetValue(""FreightAmt"", myFreightAmt) END IF ' end of myPaymentType END IF END IF


  • 2.  RE: Scripting We have a script at a client where we

    Posted 08-10-2016 09:51
    If your script trigger is not passing through a Value, that would explain the problem.


  • 3.  RE: Scripting We have a script at a client where we

    Posted 08-10-2016 11:20
      |   view attached
    @KevinMoyes I Did not write this script and the consultant that did is on vacation so please try to bear with me my ignorance. I understand the code (or think I do) , but I don't write the scripts in custom office The script is triggered on Column - Pre-validate on the field ""FreightAmt"" in SO Invoice Header. but I'm not sure what you mean by the trigger not passing a value? if the freight amount is zero would that cause this problem? I attached a screen shot if it helps


  • 4.  RE: Scripting We have a script at a client where we

    Posted 08-10-2016 11:24
    If I understand correctly, you are changing the freight amount when payment type is a credit card... although you do a oBusObj.SetValue() for all other payment types, you are NOT changing the freight amount. I seem to recall that the setvalue() method checks for that scenario and simply returns when no change has taken place. Recommend you test this theory by forcing a freight amount change for a non credit card payment type and see if it flies....


  • 5.  RE: Scripting We have a script at a client where we

    Posted 08-10-2016 11:47
    My comment was pertaining mainly to if you were using a UDF value, which can be NULL. The FreightAmt column should always be numeric. Of course, now I see the issue... you'd have recursive calls to the same script, because each time you SetValue on the FreightAmt field, the script is triggered again. When you SetValue, and use the same value, nothing happens so no error. Before your SetValue statements, deactivate the event, and afterwards set it to active again... Reference: retVal = oScript.ActivateProcedure (proc_name as String) and retVal = oScript.DeactivateProcedure (proc_name as String) These are used to give the script author the ability to avoid recursive calls. For example, if the PostValidateQuantityShipped(col, val) procedure script was to invoke the oBusObj.SetValue(""QuantityShipped"", val), this would in turn cause the PostValidateQuantityShipped(col, val) procedure to be called again. To avoid this, call retVal = oScript.DeactivateProcedure(""PostValidateQuantityShipped"") prior to the SetValue() call, then use the retVal = oScript.ActivateProcedure(""PostValidateQuantityShipped"") to reactivate this procedure. Note: Use retVal = oScript.DeactivateProcedure(""*ALL*"") to deactivate/activate all procedures for the current business object. Use retVal = oScript.Deactivate(""*"") to deactivate/activate the current procedure.


  • 6.  RE: Scripting We have a script at a client where we

    Posted 08-11-2016 05:22
    Thanks Randy and Kevin that makes perfect sense. I'll have our scripter add the Deactivate/Activate.


  • 7.  RE: Scripting We have a script at a client where we

    Posted 08-11-2016 06:42
      |   view attached
    Well that didn't seem to help. Below is the portion of the code that I changed. and attached is a screenshot of the error I'm getting. The error is occurring on the SetValue call, I can tell this because I can leave the activate/deactivate lines of code in and as long as I do a SetValueNoValidate the script fires without any errors. Note that I'm working on all of this because for some reason we get weird rounding errors if we don't force the validation. we were getting weird rounding even on freight that was not being recalculated until I changed the ""Else do nothing"" portion from ""SetValueNoValidate"" to ""SetValue"". Once I made that change the weird rounding went away on freight that did not have a credit card ELSEIF myPaymentType = ""MC"" THEN myNewFreightAmt = ROUND((myTotalInvoice * .02) + myFreightAmt,2) oScript.DeactivateProcedure(""PostValidateFreightAmt"") 'Turn off post procedure call to avoid recursive calls myRetVal = oBusObj.SetValue(""FreightAmt"",myNewFreightAmt) oScript.ActivateProcedure(""PostValidateFreightAmt"") 'Turn post procedure call back on


  • 8.  RE: Scripting We have a script at a client where we

    Posted 08-11-2016 06:56
    Your screenshot used the PreValidate event. Did you change it to PostValidate?


  • 9.  RE: Scripting We have a script at a client where we

    Posted 08-11-2016 07:45
      |   view attached
    No I didn't catch that, but now I took it out for the PreValidate and added it to PostValidate getting the same error except now the ""last Key Text"" is ""bVPST~FREIGHTAMT~500"" it used to say ""bVPRE~FREIGHTAMT~500"" ELSEIF myPaymentType = ""MC"" THEN myNewFreightAmt = ROUND((myTotalInvoice * .02) + myFreightAmt,2) myRetVal = oScript.DeactivateProcedure(""PostValidateFreightAmt"") 'To avoid recursive calls myRetVal = oBusObj.SetValue(""FreightAmt"", myNewFreightAmt) myRetVal = oScript.ActivateProcedure(""PostValidateFreightAmt"") 'Turn post procedure back on (your assistance is greatly appreciated by the way)


  • 10.  RE: Scripting We have a script at a client where we

    Posted 08-11-2016 07:50
    The Shipper ID you're using has permission to set Freight?


  • 11.  RE: Scripting We have a script at a client where we

    Posted 08-11-2016 07:56
    yes, because I can change the freight on non-credit card type of transactions and it saves the freight properly - and that section of the code is in the ""else do nothing"" portion of the code. That code even has the validation type of SetValue. which doesn't error out Else 'Do nothing myRetVal = oBusObj.SetValue(""FreightAmt"", myFreightAmt) END IF ' end of myPaymentType


  • 12.  RE: Scripting We have a script at a client where we

    Posted 08-11-2016 08:00
    That doesn't mean it is allowed, because you're setting it to the same value it already has, which doesn't trigger the event. Set it to something else (hard code a 1) and you might get a similar error. Did you double-check the Shipper ID Maintenance?


  • 13.  RE: Scripting We have a script at a client where we

    Posted 08-11-2016 08:31
    I did double check the shipper ID, (just now I'll admit) and it was already set to allow changes to freight. I added a line to the ""do nothing section to set myFreightAmt = 1 that code did not error (using a shipment that was not a credit card) and the freight was set to one dollar. So that line of code works but it the same line of code does not work in the earlier IF statement. Could it have something to do with the way these if statements are nested? I did not write that originally and it seems to be intended to work like a CASE statement. (I'm close to giving up here) IF myPaymentType = ""AMEX"" THEN myNewFreightAmt = ROUND((myTotalInvoice * .02) + myFreightAmt,2) myRetVal = oBusObj.SetValueNoValidate(""FreightAmt"",myNewFreightAmt) ELSEIF myPaymentType = ""DISC"" THEN myNewFreightAmt = ROUND((myTotalInvoice * .02) + myFreightAmt,2) myRetVal = oBusObj.SetValueNoValidate(""FreightAmt"",myNewFreightAmt) ELSEIF myPaymentType = ""MC"" THEN myFreightAmt = ROUND((myTotalInvoice * .02) + myFreightAmt,2) myretval = oScript.DeactivateProcedure(""PostValidateFreightAmt"") 'To avoid recursive calls myRetVal = oBusObj.SetValue(""FreightAmt"",myFreightAmt) myretval = oScript.ActivateProcedure(""PostValidateFreightAmt"") 'Turn post procedure back on ELSEIF myPaymentType = ""VISA"" THEN myNewFreightAmt = ROUND((myTotalInvoice * .02) + myFreightAmt,2) 'oScript.DeactivateProcedure(""PostValidateFreightAmt"") myRetVal = oBusObj.SetValueNoValidate(""FreightAmt"",myNewFreightAmt) 'oScript.ActivateProcedure(""PostValidateFreightAmt"") Else'Do nothing 'retMsg = oSession.AsObject(oSession.UI).MessageBox("""", cstr(myFreightAmt)) myRetVal = oBusObj.SetValue(""FreightAmt"",myFreightAmt) END IF ' end of myPaymentType


  • 14.  RE: Scripting We have a script at a client where we

    Posted 08-11-2016 08:35
    Add this to just above the line of code giving you the problem, to check the value being set. retVal = oSession.AsObject(oSession.UI).MessageBox(""myFreightAmt: "" & cStr(myFreightAmt)) If it doesn't pass through a number, then it's the calculation, not the SetValue giving you the problem.


  • 15.  RE: Scripting We have a script at a client where we

    Posted 08-11-2016 08:59
      |   view attached
    interesting here is a screenshot there is a colon (:) after the number is that part of the value?


  • 16.  RE: Scripting We have a script at a client where we

    Posted 08-11-2016 09:05
    the colon is not part of the variable I changed the message display line to read retVal = oSession.AsObject(oSession.UI).MessageBox(""myFreightAmt: "" & cStr(myFreightAmt)&""**"") the colon is showing after my asterisks in the display screen.


  • 17.  RE: Scripting We have a script at a client where we

    Posted 08-11-2016 09:19
      |   view attached
    Kevin, I think your correct I should be focused on the value that is trying to be set in the SetValue statement. Which makes sense with the root issue I'm having. even though we have a line of code that should be rounding the value to 2 decimal places you can look at the screenshot below and see what gets posted to sage is 159.169999999999968


  • 18.  RE: Scripting We have a script at a client where we

    Posted 08-11-2016 09:28
    I'd move the SetValue outside your nested IF's and have that done once, at the end. Bullet proof your myFreightAmt calculations (using a pop-up to verify...), then the SetValue shouldn't be a distraction (and you don't have to repeat your disable / enable statements). I think MAS has a hard-coded 6 digit decimal precision limit and if you go beyond that there will undoubtedly be issues.


  • 19.  RE: Scripting We have a script at a client where we

    Posted 08-11-2016 09:37
    great idea!


  • 20.  RE: Scripting We have a script at a client where we

    Posted 08-11-2016 10:47
    Great idea, but same results. I'm fairly convinced that the code is not seeing the variable as a number. it explains the error message and also that goofy rounding I think. I need to step away from this and look at it tomorrow with fresh eyes. if you or anyone has additional thoughts let me know; I appreciate the help; if/when I get this figured out I'll post my findings.


  • 21.  RE: Scripting We have a script at a client where we

    Posted 08-11-2016 10:53
    If the cStr is showing the correct amount, then perhaps just do a cDbl(cStr(myFreightAmt)) in your SetValue statement.