Accpac ComAPI asking for parameters

SOLVED

Hi,

I have written a console app in C# to export Purchase Orders to PDF. When using the standard Crystal file that ships with Sage 300 (POPOR01.rpt), the export works perfectly fine without requiring user intervention.

If, however, i change to the crystal file specific to Pacific Workflow (PTPOR04.rpt), a pop up shows asking for the parameters PORFROM,PORTO, QTYDEC and REPRINTPOS.

I have set all 4 these parameters in my code:

rpt.SetParam("PORFROM", item.PoOrderNum); -- Here I loop through a list of PO Numbers
rpt.SetParam("PORTO", item.PoOrderNum);

rpt.SetParam("REPRINTPOS", "1");

rpt.SetParam("QTYDEC", "2");

It still asks for the parameters, even though they are set in code. I have check the sub reports and none of the sub reports require these 4 parameters.

Has anybody ever experienced a similar issue?

  • 0

    In the porpt.ini file you'll see different sections. The section is what you're loading up when you call .ReportSelect.  You're probably calling POPOR01 or something like that.

    That section, among other things, describes the parameters that should be passed from Sage to the report.

    I suspect that since you're changing applications that you'll need to adjust the section that you're calling to something like PTPOR01.  Best to record a macro of printing the purchase order from within the PW application and see what section it is calling. Then adjust your code accordingly.

  • 0 in reply to Django

    Thanks. I see what you're saying. This is specific to Pacific Workflow (a third party module installed on top of Sage 300 ERP). When looking at the ini file for their version of Purchase Orders, I see this:

    [PTPOR04]
    heading=9500
    crystal=ptpor04
    orientation=portrait
    paper size=1
    optparams=8
    2=PATH COMPANY
    3=FILE FILEEXT
    4=QTYDEC STRING
    5=PORFROM STRING
    6=PORTO STRING
    7=REPRINTPOS STRING
    8=FROMVEND STRING
    9=TOVEND STRING

    slightly different from the standard Sage 300 ini files, but still similar. According to this ini file, it seems as though I am setting parameters correctly, but the prompt still comes up asking for the parameters that are provided.

    I have recorded a macro for printing of this report and used that to build up the code, but it's still not working correctly

  • 0 in reply to Eddie Willcox_1

    Is your code calling .ReportSelect("PTPOR04","")?

  • 0 in reply to Django

    Yes it is. I have also tried using the full path and extension to the crystal report file, but still the same issue

  • 0 in reply to Eddie Willcox_1

    You'll want to go into the registry under HKLM\Software\ACCPAC International, Inc.\ACCPAC\debug and set repcmd to "Y".

    Then print the report.  You'll see a ton of message box pop-ups that will let you know what the printing engine is doing when you're calling it.  It will walk through the loading of the section, the report, the parameters.  Don't do this on a production server during working hours. You'll drive everyone mad.

    See if that helps.

    Otherwise, without source code, everything else are guesses.

  • 0 in reply to Django

    I have changed the registry setting as suggested, but I don't see any pop-ups showing anything.

    Below is my code:

    public void PrintPuchaseOrders(List<PoOrder> poOrders)
    {
    session = new AccpacSession();
    session.Init("", "XY", "XY1000", sageVersion);

    if (!session.IsOpened)
    {
    session.Open(sageUser, sagePass, sageDb, DateTime.Now, 0, "");
    }

    //rpt = session.ReportSelect("PTPOR04", " ", " ");
    rpt = session.ReportSelect("C:\\Sage\\Sage300\\PT69A\\ENG\\PTPOR04.rpt", " ", " ");
    rptPrintSetup = session.GetPrintSetup("", "");
    rptPrintSetup.DeviceName = "Microsoft Print to PDF";
    rptPrintSetup.OutputName = "USB001:";
    rptPrintSetup.PaperSize = 9;
    rptPrintSetup.UseA4 = true;
    rptPrintSetup.UseReportOrientation = true;

    rpt.PrinterSetup(rptPrintSetup);

    rpt.SetParam("QTYDEC", "2");
    //rpt.SetParam("ACTIVE", "1");
    //rpt.SetParam("BLANKET", "1");
    //rpt.SetParam("FUTURE", "1");
    //rpt.SetParam("STANDING", "1");
    //rpt.SetParam("PRINTED", "1");
    //rpt.SetParam("DPRINTED", "1");
    //rpt.SetParam("ECENABLED", "0");
    //rpt.SetParam("DIRECTEC", "0");
    //rpt.SetParam("DELMETHOD", "1");
    //rpt.SetParam("SWDELMETHOD", "3");

    foreach (PoOrder item in poOrders)
    {
    string path = exportPath + "\\PurchaseOrders";

    rpt.SetParam("PORFROM", item.PoOrderNum);
    rpt.SetParam("PORTO", item.PoOrderNum);

    //rpt.SetParam("SORTFROM", item.PoOrderNum);
    //rpt.SetParam("SORTTO", item.PoOrderNum);

    rpt.SetParam("REPRINTPOS", "1");
    //rpt.MsgrConnect(false);
    rpt.NumOfCopies = 1;

    rpt.Destination = tagPrintDestinationEnum.PD_FILE;
    rpt.Format = tagPrintFormatEnum.PF_PDF;
    if (item.PoOrderVendor == "")
    {
    path += "\\BlankVendor";
    }
    else
    {
    path += "\\" + item.PoOrderVendor.Trim();
    }

    bool folderExists = CheckIfFolderExists(path);

    if (folderExists)
    {
    rpt.PrintDir = path + "\\" + item.PoOrderDate.Trim() + "-" + item.PoOrderNum.Trim() + "-" + item.PoOrderVendor.Trim() + ".pdf";
    try
    {
    rpt.PrintReport(); 
    //sql.UpdateLastPoSequence(item);
    sql.UpdateLastSequence("PurchaseOrder",item.PoOrderSeq,item.PoOrderNum);

    }
    catch (Exception e)
    {
    Console.WriteLine("Could not export Purchase Orders\r\n" + e.Message);
    //Console.ReadLine();
    message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " :\r\nPurchase Orders Error\r\n " + e.Message + "\r\nStack Trace: " + e.StackTrace + "\r\n";
    appPart = "PurchaseOrders";
    message += "\r\nAccpac Errors:\r\n";

    if (session.Errors.Count > 0)
    {
    for (var indx = 0; indx < session.Errors.Count; indx++)
    {
    message += "\r\n" + session.Errors.Item(indx) + "\r\n";
    Console.WriteLine(session.Errors.Item(indx));
    //Console.ReadLine();
    }
    }

    WriteErrorLog(message, appPart);
    }
    }
    }

    if (session.IsOpened)
    session.Close();

    Console.WriteLine("Purchase Orders Exported");
    }

  • +1 in reply to Eddie Willcox_1
    verified answer

    You've commented out the line that tells Sage what section to use.

    If the PTPOR04 section has a line within it that says

    Crystal=PRPOR04.RPT then you can just use:

    rpt = session.ReportSelect("PTPOR04", " ", " ");

    If you need to override the Crystal report that you want Sage to use you can do this:

    rpt = session.ReportSelect("PTPOR04[PTPOR04.rpt]", " ", " ");

    What did the macro look like when you recorded a macro of you printing the purchase order from within the PW screen?

    And for the registry entry it looks like I gave you the wrong setting: It should be set to "D"

    smist08.wordpress.com/.../

  • 0 in reply to Django

    This is what the macro looks like:

    Dim mDBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
    Set mDBLinkCmpRW = OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)

    Dim mDBLinkSysRW As AccpacCOMAPI.AccpacDBLink
    Set mDBLinkSysRW = OpenDBLink(DBLINK_SYSTEM, DBLINK_FLG_READWRITE)

    Dim temp As Boolean
    Dim rpt As AccpacCOMAPI.AccpacReport
    Set rpt = ReportSelect("PTPOR04", " ", " ")
    Dim rptPrintSetup As AccpacCOMAPI.AccpacPrintSetup
    Set rptPrintSetup = GetPrintSetup(" ", " ")
    rptPrintSetup.DeviceName = "Microsoft Print to PDF"
    rptPrintSetup.OutputName = "PORTPROMPT:"
    rptPrintSetup.Orientation = 1
    rptPrintSetup.PaperSize = 9
    rptPrintSetup.PaperSource = 15
    rpt.PrinterSetup rptPrintSetup
    rpt.SetParam "QTYDEC", "2" ' Report parameter: 4
    rpt.SetParam "PORFROM", "PO0014697" ' Report parameter: 5
    rpt.SetParam "PORTO", "PO0014697" ' Report parameter: 6
    rpt.SetParam "REPRINTPOS", "1" ' Report parameter: 7
    rpt.NumOfCopies = 1
    rpt.Destination = PD_PREVIEW
    rpt.PrintDir = ""
    rpt.PrintReport

    My issue is exactly as you have pointed out. Using this exact line 

    rpt = session.ReportSelect("PTPOR04", " ", " "); 

    fixes the issue. It is no longer asking for parameters and is doing exactly what it needs to. 

    Thank you Django for your assistance