Scripting

Expand all | Collapse all

Creating a script to calculate the sales tax on ea

Nicholas Webb

Nicholas Webb08-03-2018 13:13

Phil McIntosh

Phil McIntosh08-03-2018 15:34

  • 1.  Creating a script to calculate the sales tax on ea

    Posted 08-03-2018 13:02
    Creating a script to calculate the sales tax on each line item and put it in a UDF. Having a problem accessing the SO_SalesOrderTaxDetail object to get the tax rate. Error 88 on oTaxDet = oSession.GetObject(""SO_SalesOrderTaxDetail_bus"") How do I get from the line object to the SO_SalesOrderTaxDetail object?


  • 2.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-03-2018 13:13
    have you tried SO_SalesOrderTaxDetail_svc?


  • 3.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-03-2018 13:14
    What about: Set oTaxDet = oSession.AsObject(oSession.GetObject(""SO_SalesOrderTaxDetail_bus""))


  • 4.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-03-2018 13:24
    @NicholasWebb I had tried _svc, same result. @SteveIwanowski - same error there as well


  • 5.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-03-2018 13:37
    I believe the property you are after is SalesTaxCalcObj inherited by SO_CommonEntry. The SalesTaxCalcObj's _class property returns SY_SalesTaxCalculation_bus. I don't know whether you can get this object handle using oBusObj.SalesTaxCalcObj or by using GetObject(""SY_SalesTaxCalculation_bus"") but i do know for sure that you can get it using oScript.Evaluate(""coBusiness'SalesTaxCalcObj"").


  • 6.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-03-2018 13:53
    @PhilMcIntosh , can you try the following? ``` nTaxDetail = oSession.GetObject(""SO_SalesOrderTaxDetail_bus"") if nTaxDetail > 0 then set oTaxDetail = oSession.AsObject(nTaxDetail) ' Tax detal logic goes here else oSession.AsObject(oSession.UI).MessageBox """", ""Unable to get handle to Tax Detail object"" & vbcrlf & ""Error: "" & oSession.LastErrorMsg end if ```


  • 7.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-03-2018 14:23
    @DavidSpeckII - that works, but it gets the whole freaking file, not just this order. I tried a find and SetKey, but they didn't seem to work. Do I need to put this script on the header so I can get child objects and then loop through the lines?


  • 8.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-03-2018 14:24
      |   view attached
    Confirmed that oBusObj.SalesTaxCalcObj will work. The benefit of using this object is that you will already be on the correct record whereas using GetObject will require locating the records you are after.


  • 9.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-03-2018 14:32
    Do you really need the Tax Detail or just Tax Summary? my last post using oBusObj.SalesTaxCalcObj will get you the correct summary record, however, i did not see a property of that object handle that pointed to a line/detail object the way oBusObj.Lines works. if you do need the Tax Detail, then you will probably need to use the GetObject approach and either try a SetMode with a filter if possible or use GetResultSets.


  • 10.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-03-2018 14:35
    I do need the detail to get the rate, though I suppose I could use the summary to get the tax code and then do an ODBC query.


  • 11.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-03-2018 14:35
    @PhilMcIntosh Since it's a BUS, you'll need to use SetKeyValue and SetKey. Find is for SVC.


  • 12.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-03-2018 14:39
    I also need the class, which is also only in the detail


  • 13.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-03-2018 14:53
      |   view attached
    UPDATED the code: See if this works for you. ``` nTaxDetail = oSession.GetObject(""SO_SalesOrderTaxDetail_bus"") If nTaxDetail > 0 Then Set oTaxDetail = oSession.AsObject(nTaxDetail) ' Tax detal logic goes here sSalesOrderNo = """" : oBusObj.GetValue ""SalesOrderNo$"", sSalesOrderNo oTaxDetail.SetBrowseFilter sSalesOrderNo oTaxDetail.MoveFirst If Not(CBool(oTaxDetail.EoF)) Then Do Until CBool(oTaxDetail.EoF) oScript.DebugPrint oTaxDetail.GetKeyPadded() oTaxDetail.MoveNext Loop End If oTaxDetail.SetBrowseFilter """" Set oTaxDetail = Nothing Else oSession.AsObject(oSession.UI).MessageBox """", ""Unable to get handle to Tax Detail object"" & vbCrLf & ""Error: "" & oSession.LastErrorMsg End If ``` UPDATED the code:


  • 14.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-03-2018 15:34
    Thank you! Thank you! Thank you!!!!


  • 15.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-03-2018 16:09
    Well, damn - this is weird - it only works once you have saved the order, even though you can see the tax records on the screen, calling the object doesn't get the records in memory for the order...


  • 16.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-03-2018 16:12
    Probably has to do with the fact that the detail table likely uses set mode and therefore won't be committed to the physical file until the order is saved. Do you have to have this udf populated while on the line during editing of the order or could you run through the lines on a post-write event?


  • 17.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-03-2018 16:14
    I am thinking I am going to have to do that...Monday...


  • 18.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-06-2018 12:07
    Moved it to Sales Order Header Post-write event. I can get the sales tax rate, loop through the lines and set the UDF value, but oLines.Write() generates an error: System does not have correct permissions Details of that are: error 13 SY_SalesTaxCalculation_bus.pvc line 2686 which does not show up in the KB


  • 19.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-06-2018 12:19
    I don't believe i have ever had to modify the lines on a post write but i wouldn't be surprised if the lines object has already been cleared so i would suggest doing a GetValue on the sales order number and then do a SetKey on the header object, i believe the SetKey should perform the SetCurrentKey which should then perform SetHeader, these should cause the header to enter edit mode and also prepare the lines object with the lines related to the header.


  • 20.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-06-2018 14:12
    It didn't like that either, so I decided to move the script to the table prewrite and get the tax rate via ODBC.


  • 21.  RE: Creating a script to calculate the sales tax on ea

    Posted 08-06-2018 19:13
      |   view attached
    This should do the trick on a header post write event. The weird thing is that it was necessary to use CommitLines AND SetCurrentKey during the post write, if i used the SetKey or SetCurrentKey without CommitLines before it, i got weird errors/behavior. In my humble opinion, this seems like a bug as i would expect that during a post write event, the lines have already been committed but that didn't appear to be the case. Perhaps @AlnoorCassim might be able to provide some insight. ``` sSalesOrderNo = """" : oBusObj.GetValue ""SalesOrderNo$"", sSalesOrderNo oScript.DebugPrint ""oBusObj.CommitLines(): "" & oBusObj.CommitLines() oScript.DebugPrint ""oBusObj.SetCurrentKey(): "" & oBusObj.SetCurrentKey (sSalesOrderNo) nTaxDetail = oSession.GetObject(""SO_SalesOrderTaxDetail_bus"") If nTaxDetail > 0 Then Set oTaxDetail = oSession.AsObject(nTaxDetail) oTaxDetail.SetBrowseFilter sSalesOrderNo oTaxDetail.MoveFirst If Not(CBool(oTaxDetail.EoF)) Then Do Until CBool(oTaxDetail.EoF) oScript.DebugPrint ""oTaxDetail.GetKeyPadded(): "" & oTaxDetail.GetKeyPadded() oTaxDetail.MoveNext Loop End If oTaxDetail.SetBrowseFilter """" Set oTaxDetail = Nothing Else oSession.AsObject(oSession.UI).MessageBox """", ""Unable to get handle to Tax Detail object"" & vbCrLf & ""Error: "" & oSession.LastErrorMsg End If nLines = oBusObj.Lines oScript.DebugPrint ""oBusObj.Lines: "" & nLines If nLines > 0 Then Set oLines = oSession.AsObject(nLines) oLines.MoveFirst If Not(CBool(oLines.EoF)) Then Do Until CBool(oLines.EoF) oScript.DebugPrint ""oLines.EditState: "" & oLines.EditState oScript.DebugPrint ""oLines.GetKeyPadded(): "" & oLines.GetKeyPadded() sCommentText = """" : oLines.GetValue ""CommentText$"", sCommentText oScript.DebugPrint ""oLines.SetValue(): "" & oLines.SetValue (""CommentText$"", sCommentText & "" Updated during Post Write"") oScript.DebugPrint ""oLines.Write(): "" & oLines.Write() oLines.MoveNext Loop End If Set oLines = Nothing End If oScript.DeactivateProcedure ""PostWrite"" oScript.DebugPrint ""oBusObj.Write(): "" & oBusObj.Write() oScript.ActivateProcedure ""PostWrite"" ```