Scripting

  • 1.  I'm getting a weird error when printing an SO Invo

    Posted 08-17-2014 16:27
    I'm getting a weird error when printing an SO Invoice through the BOI. It showed up when we upgraded to Sage 100 2013, Service Update 5. It worked correctly under Service Update 3, so I'm guessing the requirements for printing have changed. The error reads: The S/O0000000038SO_INVOICEPRINTING_UI STANDARD 00001 is invalid. Here is my code. You'll see in the comments where the error happens. Any help would be greatly appreciated. Thanks. Jon ' Global Variables: Private oScript As Object Private oSS As Object Private moduleDate As DateTime Private Sub printInvoice(ByVal inv As Invoice) moduleDate = DateTime.Today Dim result As Int32 = 1 loginToMAS(""S/O"") Dim soPrint As Object result = oSS.nSetProgram(oSS.nLookupTask(""SO_InvoicePrinting_ui"")) If result = 0 Then Throw New MASException(oSS.sLastErrorMsg) soPrint = oScript.NewObject(""SO_InvoicePrinting_rpt"", oSS) oSS.nTerminateUI() Dim repSetting As String = ""STANDARD"" result = soPrint.nSelectReportSetting(repSetting) If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetKeyValue(""ReportSetting$"", repSetting) If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) ' New Code, added 8-6-14 (For compatibility with 2013) result = soPrint.nSetKeyValue(""ModuleCode$"", ""S/O"") If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) Dim sCompanyKey As String = oSS.sCompanyKey result = soPrint.nSetKeyValue(""CompanyKey$"", sCompanyKey) If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetKeyValue(""ReportID$"", ""SO_InvoicePrinting_ui"") If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetKeyValue(""RowKey$"", ""1"") If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetKey() If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) ' Set Selection criteria result = soPrint.nSetValue(""SelectField$"", ""Invoice Number"") If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetValue(""SelectFieldValue$"", ""Invoice Number"") If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetValue(""Tag$"", ""TABLE=SO_INVOICEHEADER; COLUMN=INVOICENO$"") If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetValue(""Operand$"", ""="") If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetValue(""Value1$"", inv.invoiceNo) If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetValue(""KeyReference$"", inv.invoiceNo) If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nWrite() If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetPartialRecord(""Plain"", oScript.Evaluate(""CPL(""""IOLIST TemplateDesc$"""")"")) ' THIS IS WHERE THE ERROR HAPPENS result = soPrint.nProcessReport(""PRINT"") If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) ' The error message is: The S/O0000000038SO_INVOICEPRINTING_UI STANDARD 00001 is invalid. soPrint.DropObject() cleanup() End Sub ' Here are the two helper methods I call from printInvoice: Private Sub loginToMAS(ByVal moduleCode As String) Dim result As Integer = 1 oScript = New ProvideX.Script() Dim SOTAMAS90Key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(""Software\ODBC\ODBC.INI\SOTAMAS90"") Dim InitPath As String InitPath = SOTAMAS90Key.GetValue(""Directory"") & ""\Home"" 'InitPath = My.Settings.PathToMAS & ""\Home"" 'Login to MAS oScript.Init(InitPath) oSS = oScript.NewObject(""SY_SESSION"") result = oSS.nSetUser(creds.masUserID, creds.masPassword) If result = 0 Then Throw New MASException(oSS.sLastErrorMsg) 'Select Company and Module date result = oSS.nSetCompany(creds.masCompany) If result = 0 Then Throw New MASException(oSS.sLastErrorMsg) result = oSS.nSetDate(moduleCode, moduleDate.ToString(""yyyyMMdd"")) If result = 0 Then Throw New MASException(oSS.sLastErrorMsg) result = oSS.nSetModule(moduleCode) If result = 0 Then Throw New MASException(oSS.sLastErrorMsg) End Sub Private Sub cleanup() oSS.nCleanUp() oSS.DropObject() oSS = Nothing oScript = Nothing End Sub


  • 2.  RE: I'm getting a weird error when printing an SO Invo

    Posted 08-17-2014 19:03
    That error means the report selection key is invalid. Report objects are always non-standard so conventional biz object rules don't necessarily apply. Here are a few things that might make a difference: 1. Do the SetKeyValue's in this order: ModuleCode$, CompanyKey$, ReportID$, ReportSetting$, RowKey$ 2. Don't set the RowKey to ""1"" but instead to ""00001"" (not sure if it pre-pends the leading zeroes for you) 3. When setting the Tag$ the way you see the data in DFDM it always has an ending semi-colon that is: ""TABLE=SO_INVOICEHEADER; COLUMN=INVOICENO$;"" 4. I believe but not 100% sure the KeyReference$ should be set to """" instead of inv.InvoiceNo Well hope that helps Aaron.


  • 3.  RE: I'm getting a weird error when printing an SO Invo

    Posted 08-17-2014 20:48
    Thanks, Alnoor. No luck. Here is what I changed my printInvoice method to. Also, I tried setting the KeyReference$ to """" as well as the invoice number. Thanks. Aaron Private Sub printInvoice(ByVal inv As Invoice) moduleDate = DateTime.Today Dim result As Int32 = 1 loginToMAS(""S/O"") Dim soPrint As Object result = oSS.nSetProgram(oSS.nLookupTask(""SO_InvoicePrinting_ui"")) If result = 0 Then Throw New MASException(oSS.sLastErrorMsg) soPrint = oScript.NewObject(""SO_InvoicePrinting_rpt"", oSS) oSS.nTerminateUI() Dim repSetting As String = ""STANDARD"" result = soPrint.nSelectReportSetting(repSetting) 'NMWD If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetKeyValue(""ModuleCode$"", ""S/O"") If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) Dim sCompanyKey As String = oSS.sCompanyKey result = soPrint.nSetKeyValue(""CompanyKey$"", sCompanyKey) If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetKeyValue(""ReportID$"", ""SO_InvoicePrinting_ui"") If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetKeyValue(""ReportSetting$"", repSetting) 'NMWD If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetKeyValue(""RowKey$"", ""00001"") If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetKey() If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetValue(""SelectField$"", ""Invoice Number"") If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetValue(""SelectFieldValue$"", ""Invoice Number"") If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetValue(""Tag$"", ""TABLE=SO_INVOICEHEADER; COLUMN=INVOICENO$;"") If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetValue(""Operand$"", ""="") If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetValue(""Value1$"", inv.invoiceNo) If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetValue(""KeyReference$"", inv.invoiceNo) ' TRIED """" AS WELL If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nWrite() If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) result = soPrint.nSetPartialRecord(""Plain"", oScript.Evaluate(""CPL(""""IOLIST TemplateDesc$"""")"")) result = soPrint.nProcessReport(""PRINT"") ' ERROR HAPPENS HERE If result = 0 Then Throw New MASException(soPrint.sLastErrorMsg) soPrint.DropObject() cleanup() End Sub


  • 4.  RE: I'm getting a weird error when printing an SO Invo

    Posted 08-18-2014 01:16
      |   view attached
    I tried it with VB Script as I don't have Visual Studio on this laptop. Attached. This printed an invoice to my own printer. I didn't get your error but a key difference was I set the QuickPrint flag otherwise what happens is (and you may never actually see this in the BOI) is it wants to prompt you with ""Do you want to print Sales Journal?"" and may need that value passed to it. Who knows it may have been more apparent If you didn't have the nTerminateUI() in there. One of those upgrade quirks I guess.

    Attachment(s)



  • 5.  RE: I'm getting a weird error when printing an SO Invo

    Posted 08-18-2014 06:03
    Hi Alnoor, Your script worked perfectly in 5.00.3.0, but when I upgrade to 5.00.5.0, running the script produces the same error. I tried in in my live company as well as ABX. To be clear: I just modified your script with my credentials, and the correct company code and invoice number. Saved it as a VBS file to my desktop and ran it. I did not try to integrate your script into my VB.NET program. What version of MAS are you running? Aaron


  • 6.  RE: I'm getting a weird error when printing an SO Invo

    Posted 08-18-2014 06:13
    Also, I failed to mention. Even though the script errors out, the invoice does get printed. But what happens is Cleanup() then errors out, leaving orphaned pvxcom.exe processes running, and the BOI in an unusable state. Because, in my program, printing the invoice is just one of 3 steps {writing the invoice, printing the invoice, and running daily sales report/update}, it breaks the workflow and makes the app unusable by the client.


  • 7.  RE: I'm getting a weird error when printing an SO Invo

    Posted 08-18-2014 07:38
    I was on 2014 PU3. That's about the best I could do in the middle of the night. Sorry!