Scripting

  • 1.  I am new to scripting and have created a script to

    Posted 06-21-2018 13:27
    I am new to scripting and have created a script to add up the total cost of the lines on a Sales Order and then calculate the profit margin % and populate 2 UDFs on the totals tab. If I run the script as a table pre-write from the SO Header, it will display the Total Cost and Profit Margin % after I accept the order and go back into it. I have found 2 ways to get the script to write when lines are being entered and I select the totals tab (PTotals Panel PostLoad and SO Header Pre-Total), but when I click accept, I'm getting popup boxes one after the other saying ""TotalSales"" (one popup for each line entered, i.e. 5 lines nets 5 popups of ""TotalSales"") and ""CalculatedMargin"". The script is working correctly and is calculating the Total Cost and Gross Margin % correctly, it's just giving me those popups. What do I need to change to prevent those popup boxes? Or what steps should I do different to achieve this? TotalSales = 0 TotalCost = 0 CalculatedMargin = 0 ' Set oLines = oBusObj.AsObject(oBusObj.Lines) oLines.MoveFirst() ' WHILE oLines.Eof<1 tmp=oLines.GetValue(""ItemType$"",lineItemType) IF lineItemType=""1"" then tmp=oLines.GetValue(""QuantityOrdered"",QuantityOrdered) tmp=oLines.GetValue(""ExtensionAmt"",lineExtensionAmt) tmp=oLines.GetValue(""UnitCost"",lineUnitCost) TotalSales = TotalSales + lineExtensionAmt TotalCost = TotalCost + (lineUnitCost*quantityOrdered) end if oLines.MoveNext() WEND ' if TotalSales<>0 and TotalCost <>0 then CalculatedMargin = ((TotalSales-TotalCost)/TotalSales)*100 else CalculatedMargin = 0 end if ' 'Set Total Cost and Margin retVal = oBusObj.SetValue(""UDF_TOTAL_COST"", TotalCost) retVal = oBusObj.SetValue(""UDF_MARGIN"", CalculatedMargin)


  • 2.  RE: I am new to scripting and have created a script to

    Posted 06-21-2018 13:43
    Chris, are you sure you don't have a MSGBOX command in your script? What does the pop up message look like? Is it a standard Sage message or is it simpler?


  • 3.  RE: I am new to scripting and have created a script to

    Posted 06-21-2018 13:45
      |   view attached
    At one time I tried adding a message box to the script, but it's not in the script I'm using.


  • 4.  RE: I am new to scripting and have created a script to

    Posted 06-21-2018 13:52
    Make sure you don't have other scripts active within the panel / objects. Remember that if you delete all scripts for an event, that recompiling won't get rid of the .vbs file out of MAS90\CM\Script\, which is something you'd need to remove manually.


  • 5.  RE: I am new to scripting and have created a script to

    Posted 06-21-2018 14:01
    Pop-ups as in the TotalSales MessageBox on your screenshot above or something else? Also, did you say you have 2 scripts running - one UI script on PTotals Panel PostLoad and the other a biz script on PreTotals? If so, and the above code is all you need to run, then you don't need both. PreTotals is more designed for what you have above, meaning if the same is in your UI script, you can add an Exit Sub to the top of it, recompile it, close down S/O Entry, reopen it, try again. On a side note it appears you are trying to do a VB MsgBox instead of the MessageBox() method. Although it works in Standard, it won't in Advanced and Premium in case your client is on that. Change it something like this: sMsg = ""Total Sales = "" & nTotalSales retMsg = oSession.AsObject(oSession.UI).MessageBox("""", sMsg)


  • 6.  RE: I am new to scripting and have created a script to

    Posted 06-21-2018 14:01
    Kevin, you nailed it. I had another similar script set up in my demo data that I was testing with as well. I was able to save without those popups. On another tangent, I removed the tmp=oLines.GetValue(""ItemType$"",lineItemType) IF lineItemType=""1"" then and End If in order to capture the unit price/cost of Misc Items as well, but the script still isn't totaling those up in this calculation. What can I do to capture Misc. Items as well?