Quantcast
Channel: Sage 100
Viewing all articles
Browse latest Browse all 36990

Forum Post: SO Picking Sheet Printing from BOI in C#

$
0
0
First, sorry for the long post, but I've found seeing others code on here very helpful, so I've posted the full c# function below. My issue is trying to print Sales Order Picking sheets from BOI. In the function below, if I quick print, this works. But, if I try to do a full print, I get an error at the nSetKey Method. The return value from nSetKey is 2, The errorMsg is “The S/O0000000028SO_PICKINGSHEETPRINTING_UI\0\0\0\0STANDARD\0\0\0\0\0\0\0\0\0\0\0\000001 is invalid. ” Again, works fine in quick print, the user has printed the 'Standard' form before. On a second note, this is printing (in quick print) directly to the workstation default printer. I'd actually like to fill in the details, then present the options to the user to change setting and/or print location. Any help getting the UI up would be appreciated. And last, a note to BL, yes, I'm taking the BOI course online... just haven't completed it yet. So if the answers are there, then I apologize for asking before completing the course :) private void PrintPickingSheet(string SalesOrderNo, bool QuickPrint)         {             object retVal;             string MethodName = string.Empty;             object[] Parameters;             // Instantiate a ProvidexX.Script object and initialize with the path to MAS90\Home             using (DispatchObject pvx = new DispatchObject("ProvideX.Script"))             {                 //Note: Sage 100 Advanced, use server location                 pvx.InvokeMethod("Init", @"\\srvsage100adv\Sage\Sage 100 Advanced ERP\MAS90\Home");                 // Instantiate a new Session object and initialize the session                 // by setting the user, company, date and module                 using (DispatchObject oSS = new DispatchObject(pvx.InvokeMethod("NewObject", "SY_Session")))                 {                     oSS.InvokeMethod("nSetUser", UID, PWD);                     oSS.InvokeMethod("nSetCompany", CompanyCode);                     oSS.InvokeMethod("nLogon");                     oSS.InvokeMethod("nSetDate", "S/O", DateTime.Now.Year.ToString("D4") + DateTime.Now.Month.ToString("D2") + DateTime.Now.Day.ToString("D2"));                     oSS.InvokeMethod("nSetModule", "S/O");                     //Set Program to SO_PickingSheetPrinting                     int TaskID = (int)oSS.InvokeMethod("nLookupTask", "SO_PickingSheetPrinting_ui");                                         retVal = oSS.InvokeMethod("nSetProgram", TaskID);                                          // Instantiate a SO_PickingSheetPrinting object using SO_PickingSheetPrinting_rpt                     using (DispatchObject SO_PickingSheetPrinting_rpt = new DispatchObject(pvx.InvokeMethod("NewObject", "SO_PickingSheetPrinting_rpt", oSS.GetObject())))                                         {                                                  //Select the Template Record.                         //The record must exist for the user/company, which means                         //the user you are logging in as must have printed/previewed                         //the form at least once in Sage 100                                                                             Parameters = new object[] { "STANDARD" };                         MethodName = "nSelectReportSetting";                         retVal = SO_PickingSheetPrinting_rpt.InvokeMethodByRef(MethodName, Parameters);                         if ((int)retVal != 1)                         {                             HandleError(retVal, MethodName, Parameters, SO_PickingSheetPrinting_rpt.GetProperty("sLastErrorMsg"));                         }                         if(QuickPrint)                         {                             retVal = SO_PickingSheetPrinting_rpt.SetProperty("sQuickPrint", SalesOrderNo);                             //Call ProcessReport to execute the printout                             //Available Print Destinations                             //PRINT = Print to printer                             //PREVIEW = Preview (requires UI)                             //DEFERED = print to deferred                                                          Parameters = new object[] { "PRINT" };                             MethodName = "nProcessReport";                             retVal = SO_PickingSheetPrinting_rpt.InvokeMethodByRef(MethodName, Parameters);                             if ((int)retVal != 1)                             {                                 HandleError(retVal, MethodName, Parameters, SO_PickingSheetPrinting_rpt.GetProperty("sLastErrorMsg"));                             }                         }                         else                         {                             Parameters = new object[] { "ModuleCode$", "SO" };                             MethodName = "nSetKeyValue";                             retVal = SO_PickingSheetPrinting_rpt.InvokeMethodByRef(MethodName, Parameters);                             if ((int)retVal != 1)                             {                                 HandleError(retVal, MethodName, Parameters, SO_PickingSheetPrinting_rpt.GetProperty("sLastErrorMsg"));                             }                             Parameters = new object[] { "ReportID$", "SO_PickingSheetPrinting_ui" };                             MethodName = "nSetKeyValue";                             retVal = SO_PickingSheetPrinting_rpt.InvokeMethodByRef(MethodName, Parameters);                             if ((int)retVal != 1)                             {                                 HandleError(retVal, MethodName, Parameters, SO_PickingSheetPrinting_rpt.GetProperty("sLastErrorMsg"));                             }                             Parameters = new object[] { "ReportSetting$", "STANDARD" };                             MethodName = "nSetKeyValue";                             retVal = SO_PickingSheetPrinting_rpt.InvokeMethodByRef(MethodName, Parameters);                             if ((int)retVal != 1)                             {                                 HandleError(retVal, MethodName, Parameters, SO_PickingSheetPrinting_rpt.GetProperty("sLastErrorMsg"));                             }                             Parameters = new object[] { "RowKey$", Test.ToString() };                             MethodName = "nSetKeyValue";                             retVal = SO_PickingSheetPrinting_rpt.InvokeMethodByRef(MethodName, Parameters);                             if ((int)retVal != 1)                             {                                 HandleError(retVal, MethodName, Parameters, SO_PickingSheetPrinting_rpt.GetProperty("sLastErrorMsg"));                             }                             Parameters = new object[] { "CompanyKey$", "0000000028" }; //ToDo - Pickup CompanyKey from oSS                             MethodName = "nSetKeyValue";                             retVal = SO_PickingSheetPrinting_rpt.InvokeMethodByRef(MethodName, Parameters);                             if ((int)retVal != 1)                             {                                 HandleError(retVal, MethodName, Parameters, SO_PickingSheetPrinting_rpt.GetProperty("sLastErrorMsg"));                             }                                                      Parameters = new object[] { "" };                             MethodName = "nSetKey";                             retVal = SO_PickingSheetPrinting_rpt.InvokeMethod(MethodName);                             if ((int)retVal != 1)                             {                                 HandleError(retVal, MethodName, Parameters, SO_PickingSheetPrinting_rpt.GetProperty("sLastErrorMsg"));                             }                             Parameters = new object[] { "SelectField$", "Order Number" };                             MethodName = "nSetValue";                             retVal = SO_PickingSheetPrinting_rpt.InvokeMethodByRef(MethodName, Parameters);                             if ((int)retVal != 1)                             {                                 HandleError(retVal, MethodName, Parameters, SO_PickingSheetPrinting_rpt.GetProperty("sLastErrorMsg"));                             }                             Parameters = new object[] { "SelectFieldValue$", "Order Number" };                             MethodName = "nSetValue";                             retVal = SO_PickingSheetPrinting_rpt.InvokeMethodByRef(MethodName, Parameters);                             if ((int)retVal != 1)                             {                                 HandleError(retVal, MethodName, Parameters, SO_PickingSheetPrinting_rpt.GetProperty("sLastErrorMsg"));                             }                             Parameters = new object[] { "Tag$", "TABLE=SO_SALESORDERHEADER; COLUMN=SALESORDERNO$" };                             MethodName = "nSetValue";                             retVal = SO_PickingSheetPrinting_rpt.InvokeMethodByRef(MethodName, Parameters);                             if ((int)retVal != 1)                             {                                 HandleError(retVal, MethodName, Parameters, SO_PickingSheetPrinting_rpt.GetProperty("sLastErrorMsg"));                             }                             Parameters = new object[] { "Operand$", "=" };                             MethodName = "nSetValue";                             retVal = SO_PickingSheetPrinting_rpt.InvokeMethodByRef(MethodName, Parameters);                             if ((int)retVal != 1)                             {                                 HandleError(retVal, MethodName, Parameters, SO_PickingSheetPrinting_rpt.GetProperty("sLastErrorMsg"));                             }                             Parameters = new object[] { "Value1$", SalesOrderNo };                             MethodName = "nSetValue";                             retVal = SO_PickingSheetPrinting_rpt.InvokeMethodByRef(MethodName, Parameters);                             if ((int)retVal != 1)                             {                                 HandleError(retVal, MethodName, Parameters, SO_PickingSheetPrinting_rpt.GetProperty("sLastErrorMsg"));                             }                             //Parameters = new object[] { "Value2$", SalesOrderNo2 };                             //MethodName = "nSetValue";                             //retVal = SO_SalesOrderPrinting_rpt.InvokeMethodByRef(MethodName, Parameters);                             //if ((int)retVal != 1)                             //{                             //    HandleError(retVal, MethodName, Parameters, SO_PickingSheetPrinting_rpt.GetProperty("sLastErrorMsg"));                             //}                                                          Parameters = new object[] { "" };                             MethodName = "nWrite";                             retVal = SO_PickingSheetPrinting_rpt.InvokeMethod(MethodName);                             if ((int)retVal != 1)                             {                                 HandleError(retVal, MethodName, Parameters, SO_PickingSheetPrinting_rpt.GetProperty("sLastErrorMsg"));                             }                             //Call ProcessReport to execute the printout                             //Available Print Destinations                             //PRINT = Print to printer                             //PREVIEW = Preview (requires UI)                             //DEFERED = print to deferred                                                          Parameters = new object[] { "PRINT" };                             MethodName = "nProcessReport";                             retVal = SO_PickingSheetPrinting_rpt.InvokeMethodByRef(MethodName, Parameters);                             if ((int)retVal != 1)                             {                                 HandleError(retVal, MethodName, Parameters, SO_PickingSheetPrinting_rpt.GetProperty("sLastErrorMsg"));                             }                         }                     }                 }             }          }

Viewing all articles
Browse latest Browse all 36990

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>