Guest User

Untitled

a guest
Dec 13th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. '-------------------------------------------------
  2. ' Sage 100 BOI script demonstrating a printing issue with Sage 100 - 2018.
  3. '-------------------------------------------------
  4. ' To replicate: create a new Shipping data entry in Sage, do not print it and take a note of the invoice number.
  5. ' Then enter that invoice number when prompted by this script.
  6. ' The issue is replicated when the following error message shows up:
  7. '-------------------------------------------------
  8. ' Unable to print SO_Invoice1.rpt.
  9. ' Unable to cast COM object of type 'CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass'
  10. ' to interface type 'CrystalDecisions.ReportAppServer.Controllers.ISCRReportSource'.
  11. ' This operation failed because the QueryInterface call on the COM component for the interface with IID
  12. ' '{98CDE168-C1BF-4179-BE4C-F2CFA7CB8398}' failed due to the following error: No such interface supported
  13. ' (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). - ErrorNum = CI_Report_Unable
  14. '-------------------------------------------------
  15.  
  16. Sub errchk(r, desc, oss, o)
  17. if (r = 0) then
  18. MsgBox(desc & ": " & o.sLastErrorMsg)
  19. oss.nCleanup()
  20. oss.DropObject()
  21. Set oss = Nothing
  22. WScript.Quit
  23. end if
  24. end sub
  25.  
  26. Function replace_npchars(s)
  27. smsg = ""
  28. for i=1 to Len(msg)
  29. code=Asc(Mid(msg, i, 1))
  30. if (code < 32 or code > 160) then
  31. smsg = smsg & "#" & code
  32. else
  33. smsg = smsg & Mid(msg, i, 1)
  34. end if
  35. next
  36. replace_npchars = smsg
  37. end function
  38.  
  39. Const HKEY_CURRENT_USER = &H80000001
  40. Set oReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
  41. RetVal = oReg.GetExpandedStringValue(HKEY_CURRENT_USER,"Software\Sage Software\MAS 90 Business Desktop\Settings", _
  42. "MAS90RootDirectory",PathRoot)
  43. if retVal <> 0 then
  44. oReg.GetExpandedStringValue HKEY_CURRENT_USER,"Software\ODBC\ODBC.INI\SOTAMAS90","Directory",PathRoot
  45. end if
  46.  
  47. PathHome = PathRoot & "\Home"
  48. Set oReg = Nothing
  49.  
  50. MsgBox("PathHome: " & PathHome)
  51.  
  52. Set oScript = CreateObject ("ProvideX.Script")
  53.  
  54. 'oScript.TraceOn=true
  55.  
  56. oScript.Init(Pathhome)
  57. Set oSS = oScript.NewObject("SY_Session")
  58. retVAL = oSS.nLogon()
  59. If retVAL = 0 Then
  60. User = Trim(InputBox("Enter User Name", "", "alex"))
  61. Password = Trim(InputBox("Enter Password", "", ""))
  62. retVAL = oSS.nSetUser(User,Password)
  63. errchk retVal, "SetUser", oss, oScript
  64. End If
  65.  
  66. sCompany = oSS.sCompanyCode
  67. sCompany = Trim(InputBox("Enter Company Code","Company Code",sCompany))
  68. retVAL = oSS.nSetCompany(sCompany)
  69. errchk retVal, "SetCompany", oSS, oSS
  70.  
  71. sDate = oSS.sModuleDate
  72. if sDate = "" then
  73. sDate = Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2)
  74. end if
  75. retVAL = oSS.nSetDate("S/O",sDate)
  76. errchk retVal, "SetDate", oSS, oSS
  77.  
  78. retVal = oSS.nSetModule("S/O")
  79. errchk retVal, "Set Module", oSS, oSS
  80.  
  81. str = Trim(InputBox("Enter Invoice Number","Invoice Number", "0100069"))
  82.  
  83. oSEC = oSS.nSetProgram(oSS.nLookupTask("SO_Shipping_UI"))
  84. Set oSEC_Shipping = oSS.oSecurity
  85. Set s = oScript.NewObject("SO_Shipping_Bus", oSS)
  86.  
  87. sInvoiceNumber = str
  88.  
  89. if (str <> "") then
  90. r = s.nFind(sInvoiceNumber)
  91. errchk r, "Invoice Number Find failed", oSS, s
  92.  
  93. r = s.nSetKey(sInvoiceNumber)
  94. errchk r, "Invoice Number SetKey failed", oSS, s
  95. else
  96. r = s.nGetNextInvoiceNo(sInvoiceNumber)
  97. errchk r, "GetNextInvoiceNumber failed", oSS, s
  98.  
  99. MsgBox("New Invoice Number " & sInvoiceNumber)
  100. end if
  101.  
  102. r = s.nSetKey(sInvoiceNumber)
  103. errchk r, "Setting Key on invoice number", oSS, s
  104.  
  105. 'retVAL = oSS.nSetProgram(oSS.nLookupTask("SO_PACKINGLISTPRINTING_UI"))
  106. retVAL = oSS.nSetProgram(oSS.nLookupTask("SO_INVOICEPRINTING_UI"))
  107. errchk retVal, "SetProgram", oSS, oSS
  108.  
  109. 'Set oPrint = oScript.NewObject("SO_PACKINGLISTPRINTING_RPT",oSS)
  110. Set oPrint = oScript.NewObject("SO_INVOICEPRINTING_RPT",oSS)
  111.  
  112. oSS.nTerminateUI
  113.  
  114. sFormCode = "STANDARD"
  115. sFormCode = Trim(InputBox("Enter Form Code",,sFormCode))
  116.  
  117. retVal = oPrint.nSelectReportSetting( sFormCode )
  118. errchk retVal, "Select Report Setting", oSS, oPrint
  119.  
  120. sCompanyKey = oSS.sCompanyKey
  121. retVal = oPRINT.nSetKeyValue( "ModuleCode$", "S/O" )
  122. retVal = oPRINT.nSetKeyValue("CompanyKey$", sCompanyKey)
  123. retVal = oPRINT.nSetKeyValue( "ReportID$", "SO_INVOICEPRINTING_UI" )
  124. RetVal = oPRINT.nSetKeyValue( "ReportSetting$", sFormCode )
  125. RetVal = oPRINT.nSetKeyValue( "RowKey$", "1" )
  126. RetVal = oPRINT.nSetKey
  127. errchk retVal, "SetKey - select report", oSS, oPrint
  128.  
  129. 'retval = oPrint.nSetPartialRecord("Plain", oScript.Evaluate("CPL(""IOLIST TemplateDesc$"")") )
  130. retval = oPrint.nSetPartialRecord(sFormCode, oScript.Evaluate("CPL(""IOLIST TemplateDesc$"")") )
  131. errchk retVal, "SetPartialRecord", oSS, oPrint
  132.  
  133. ' Set Selection criteria
  134. RetVal = oPRINT.nSetValue( "SelectField$", "Invoice Number" )
  135. errchk retVal, "SetValue - SelectField", oSS, oPrint
  136. RetVal = oPRINT.nSetValue( "SelectFieldValue$", "Invoice Number" )
  137. errchk retVal, "SetValue - SelectFieldValue", oSS, oPrint
  138. RetVal = oPRINT.nSetValue( "Tag$", "TABLE=SO_INVOICEHEADER; COLUMN=INVOICENO$" )
  139. errchk retVal, "SetValue - Table", oSS, oPrint
  140. RetVal = oPRINT.nSetValue( "Operand$", "=" )
  141. errchk retVal, "SetValue - Operand", oSS, oPrint
  142. RetVal = oPRINT.nSetValue( "Value1$", sInvoiceNumber )
  143. errchk retVal, "SetValue - Value1", oSS, oPrint
  144.  
  145. 'Write report setting to memory
  146. RetVal = oPRINT.nWrite
  147. errchk retVal, "Write settings", oSS, oPrint
  148.  
  149. RetVal = oPRINT.nProcessReport( "PRINT" )
  150. If retVAL = 0 Then
  151. msg = oPrint.sLastErrorMsg
  152. MsgBox("nProcessReport error: " & msg & " - ErrorNum = " & oPrint.sLastErrorNum)
  153. Else
  154. MsgBox("nProcessReport Success")
  155. end if
  156.  
  157.  
  158. on error resume next
  159. oSS.nCleanUp ()
  160. if (Err.Number <> 0) then
  161. MsgBox("Warning: Exception while oSS.nCleanUp call, ignoring and continuing: " & Err.Description)
  162. end if
  163.  
  164. oSS.DropObject()
  165. Set oSS = Nothing
  166. Set oScript = Nothing
  167.  
  168. MsgBox("Completion")
Add Comment
Please, Sign In to add comment