Scripting

  • 1.  Need SO Header Totals when arriving at Totals tab.

    Posted 09-23-2016 20:08
    Need SO Header Totals when arriving at Totals tab. I hope I'm not missing something simple, but I have a script to calculate a SO Line Cost Extension UDF and then am feeding the total of that field to the SO Header tab into a 2nd UDF using Custom Office ""Totals From Lines"" and that works fine. My next step is to calculate Tax Sales + Nontax Sales as Total Sales, then calculate Gross Profit $ and % and set into 2 more UDFs. I can see this working with the script set to Pre-Write, but is there any way I can get the fields to calculate when I click on Totals tab rather than Accept? I've tried various combinations of Table Post-Read, Column Post-Validate, etc but nothing is working. TIA for any tips!


  • 2.  RE: Need SO Header Totals when arriving at Totals tab.

    Posted 09-23-2016 22:38
    If on 2015 or higher you can try your GP code on a UI script on Panel PostLoad of pTotals. I don't know off top of my head if it would execute before or after your Pre-Totals but you can test. Also since main piece of Sage logic that runs when clicking Totals is to calc Sales Tax (and all related tax detail), if it does that using SetValue (not sure about that) then presumably a column Post-Validate script on SalesTaxAmt could fire off so you can set the GP UDFs. I dunno try it.


  • 3.  RE: Need SO Header Totals when arriving at Totals tab.

    Posted 09-24-2016 07:20
    Couldn't you update these totals after you write each line?


  • 4.  RE: Need SO Header Totals when arriving at Totals tab.

    Posted 09-25-2016 20:28
    Alnoor - thank you for introducing me to the ""Panel PostLoad""...I read the Help files on it and understand a little about how it's used. I couldn't use Column Post-Validate on Taxable Amount, Nontaxable Amount or Sales Tax since those fields are not available for some reason, but the Panel Post-Load does seem to work as long as I have a Tax Schedule assigned prior to reaching the Totals tab. If I don't though, I get the following error (see attached), which seems to be related to your comment about calculation order. Do you have any thoughts on how I can prevent this from happening besides warning my client to have default tax schedules assigned? Michael, can you clarify how to update totals after each line? Is that related to some code within the script or the Event assigned to the script in UDF Maintenance?


  • 5.  RE: Need SO Header Totals when arriving at Totals tab.

    Posted 09-25-2016 21:33
    Makes a lot of sense you need a Tax Schedule assigned for your type of script but I thought system gives you a ""valid tax schedule must be entered"" msg anyway. So seems like you should enforce it yourself. Several ways (all untested of course) - use the one that works: 1) UI Script: On your current script Panel PostLoad of pTotals sTaxSch = """" retVal = oBusObj.GetValue(""TaxSchedule$"", sTaxSch) If sTaxSch = """" Then sMsg = ""Please enter a Tax Schedule."" retMsg = oSession.AsObject(oSession.UI).MessageBox("""", sMsg) retVal = oScript.InvokeButton(""fldr.pHeader"") Exit Sub Else 'Run the current GP calc but watch for Division by Zero situations End If 2) Panel PostLoad of pAddress of pLines - same as No 1 but dont' run GP calc. 3) UI Script: Panel OnExit script of pHeader sTaxSch = """" retVal = oBusObj.GetValue(""TaxSchedule$"", sTaxSch) If sTaxSch = """" Then sMsg = ""Please enter a Tax Schedule first."" retMsg = oSession.AsObject(oSession.UI).MessageBox("""", sMsg) retVal = oUIObj.SetFolderState(""pAddress,pLines,pTotals"", ""DISABLE"") Else retVal = oUIObj.SetFolderState(""pAddress,pLines,pTotals"", ""ENABLE"") End If 4) Pre-Validate of CustomerNo CustNo = value : DivNo = """" : sTaxSch = """" retVal = oBusObj.GetValue(""ARDivisionNo$"", DivNo) FullCustNo = DivNo & CustNo Set oCust = oBusObj.AsObject(oBusObj.GetChildHandle(""CustomerNo"")) Found = oCust.Find(FullCustNo) If Found = 1 Then retVal = oCust.Find(""TaxSchedule$"", sTaxSch) If sTaxSch = """" Then sMsg = ""Oops default tax schdule is missing for "" & DivNo&""-""&CustNo retVal = oScript.SetError(sMsg) 'or instead of error use MessageBox to give a warning End If Also Michael might be saying on Line Post-Write (or on Pre-Totals by traversing the lines from top to bottom) accumulate the ExtensionAmt but separate the Taxable Amt from Nontaxable Amt into your separate variables (maybe check the Tax Class for TX vs NT vs others). Then regardless on Pre-Totals do the GP calcs and the 2 UDF SetValue's and you're done. I like this because the issue with using UI scripts is just that it won't work if say you're V/I importing these orders or web service importing these orders (there's no UI). However you would need to be certain there are no exemptions in play that would make TX lines nontaxable. Of course I can't really speak for Michael :)


  • 6.  RE: Need SO Header Totals when arriving at Totals tab.

    Posted 09-26-2016 06:10
    Is @AlnoorCassim said, I was suggesting a script to do the calculations at the line level. If after each line (PostWrite or PostDelete) you update UDF_ExtPrice and UDF_ExtCost etc, the math is already done by the time you get to the Totals tab. I've found that easier than to mess around with Pre-Totals.


  • 7.  RE: Need SO Header Totals when arriving at Totals tab.

    Posted 09-26-2016 06:26
    Thank you both for helping! Alnoor, thanks for the detailed options. I will force population of the Tax Schedule to get around this since I was lucky to get as far as I did :) Michael, I do have one script already calculating the line totals, but then need to calculate a second time against them at the order level.


  • 8.  RE: Need SO Header Totals when arriving at Totals tab.

    Posted 09-26-2016 07:32
    Messing with triggers brings back nightmares of hours lost attempting the seemingly ""simple"" but impossible. I'd go with a details script and using oHeader to update any order level calculations on the fly, as each order line is written. Beware Alnoor's option #3. It might not let you close the panel, ever (...I remember that one from the NOLA scripting class).


  • 9.  RE: Need SO Header Totals when arriving at Totals tab.

    Posted 09-26-2016 08:00
    Kevin that was because of the oUIObj.SetVar(""IGNORE_EXIT"",1) but point well taken.


  • 10.  RE: Need SO Header Totals when arriving at Totals tab.

    Posted 09-26-2016 08:05
    (Of course you're correct... I just checked the script. I remembered the field validation on a UI script causing the problem, not the command).