Function request API error

I want to simulate a print preview and then request an API.

This is the result of clicking Preview.

Now I’ve written code in function to request the API

var context=Ice.Services.ContextFactory.CreateContext<ErpContext>();
var erpContext=new Erp.Internal.Lib.CCredChk(context);
Ice.Contracts.BAQReportSvcContract bAQReportSvc=Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.BAQReportSvcContract>(erpContext.Db,true);
Ice.Tablesets.BAQReportTableset  bAQReportTableset=new Ice.Tablesets.BAQReportTableset();

try
{

     string pcReportID="BAQRptTest";
     string maintProgram="Ice.UIRpt.BAQRptTest";
     string PrintProgram="reports/CustomReports/BAQRptTest";


    
     Ice.Tablesets.BAQReportParamRow bAQReportParamRow=new Ice.Tablesets.BAQReportParamRow();
     Ice.Tablesets.ReportStyleRow  reportStyleRow= new Ice.Tablesets.ReportStyleRow();
     //Parameter
     bAQReportParamRow.UserID=this.callContextClient.CurrentUserId;
     bAQReportParamRow.Filter1="5404";
     bAQReportParamRow.AutoAction="SSRSPREVIEW";
     bAQReportParamRow.ReportStyleNum=1;
     bAQReportParamRow.WorkstationID=this.callContextClient.CurrentUserId;
     bAQReportParamRow.SSRSRenderFormat="PDF";
     bAQReportParamRow.RowMod="A";
     bAQReportParamRow.ReportID=pcReportID;
     bAQReportParamRow.ReportCurrencyCode="CNY";
     bAQReportParamRow.ReportCultureCode="zh-CN";
     bAQReportParamRow.DateFormat= "m/d/yyyy";
     bAQReportParamRow.NumericFormat=",.";
     bAQReportTableset.BAQReportParam.Add(bAQReportParamRow);
    
     //ReportStyle
     //Search ReportStyle  
     var ReportStyeResult= from ReportStye in erpContext.Db.ReportStyle where  ReportStye.ReportID==pcReportID  select ReportStye;
     
     if(ReportStyeResult.Count()>0)
     {
         reportStyleRow.Company=ReportStyeResult.FirstOrDefault().Company;
         reportStyleRow.ReportID=ReportStyeResult.FirstOrDefault().ReportID;
         reportStyleRow.StyleNum=ReportStyeResult.FirstOrDefault().StyleNum;
         reportStyleRow.StyleDescription=ReportStyeResult.FirstOrDefault().StyleDescription;
         reportStyleRow.RptTypeID=ReportStyeResult.FirstOrDefault().RptTypeID;
         reportStyleRow.PrintProgram=ReportStyeResult.FirstOrDefault().PrintProgram;
         reportStyleRow.PrintProgramOptions=ReportStyeResult.FirstOrDefault().PrintProgramOptions;
         reportStyleRow.RptDefID=ReportStyeResult.FirstOrDefault().RptDefID;
         reportStyleRow.CompanyList=ReportStyeResult.FirstOrDefault().CompanyList;
         reportStyleRow.ServerNum=ReportStyeResult.FirstOrDefault().ServerNum;
         reportStyleRow.OutputLocation=ReportStyeResult.FirstOrDefault().OutputLocation;
         reportStyleRow.OutputEDI=ReportStyeResult.FirstOrDefault().OutputEDI;
         reportStyleRow.SystemFlag=ReportStyeResult.FirstOrDefault().SystemFlag;
         reportStyleRow.CGCCode=ReportStyeResult.FirstOrDefault().CGCCode;
         reportStyleRow.SysRevID=0;
         reportStyleRow.SysRowID=ReportStyeResult.FirstOrDefault().SysRowID;
         reportStyleRow.RptCriteriaSetID=ReportStyeResult.FirstOrDefault().RptCriteriaSetID;
         reportStyleRow.RptStructuredOutputDefID=ReportStyeResult.FirstOrDefault().RptStructuredOutputDefID;
         reportStyleRow.StructuredOutputEnabled=ReportStyeResult.FirstOrDefault().StructuredOutputEnabled;
         reportStyleRow.RequireSubmissionID=ReportStyeResult.FirstOrDefault().RequireSubmissionID;
         reportStyleRow.AllowResetAfterSubmit=ReportStyeResult.FirstOrDefault().AllowResetAfterSubmit;
         reportStyleRow.CertificateID=ReportStyeResult.FirstOrDefault().CertificateID;
         reportStyleRow.LangNameID=ReportStyeResult.FirstOrDefault().LangNameID;
         reportStyleRow.FormatCulture=ReportStyeResult.FirstOrDefault().FormatCulture;
         reportStyleRow.StructuredOutputCertificateID=ReportStyeResult.FirstOrDefault().StructuredOutputCertificateID;
         reportStyleRow.StructuredOutputAlgorithm=ReportStyeResult.FirstOrDefault().StructuredOutputAlgorithm;
         reportStyleRow.StatusCode=ReportStyeResult.FirstOrDefault().StatusCode;
         reportStyleRow.StatusDesc=ReportStyeResult.FirstOrDefault().StatusDesc;
         bAQReportTableset.ReportStyle.Add(reportStyleRow);

         
     }
     throw new Ice.BLException(Newtonsoft.Json.JsonConvert.SerializeObject(bAQReportTableset));
     bAQReportSvc.TransformAndSubmit(bAQReportTableset,"",0,0,maintProgram);
     
}
catch(Exception ex)
{
    throw new Ice.BLException("Data: " + ex.Data + "Source: " + ex.Source + "Message: " + ex.Message+"StackTrace: "+ex.StackTrace);
}
finally
{
   context.Dispose();
   erpContext.Dispose();
}

An error Invalid dataset was reported while requesting a TransformAndSubmit

Then I printed out bAQReportTableset and put it in the Rest API for debugging and the request was successful

So I am very confused, is it the problem of my code, have you encountered similar problems, can you help me…

1 Like

Don’t do this.

Let’s see the full payload you are passing.

3 Likes

I would suggest using GetNewBAQReportParam(string ->ReportID) instead of creating the Tableset\Params manually.

It returns a BAQReportTableset.

Looking at the decomp, the error you see is thrown if ds is null or ds.BAQReportParam count = 0

4 Likes

Here’s how I returned bAQReportTableset before the function requested TransformAndSubmit

bAQReportSvc.TransformAndSubmit(bAQReportTableset,“”,0,0,maintProgram);

returned bAQReportTableset Json

{
    "BAQReportParam": [
        {
            "ColumnNames": 0,
            "BAQID": "",
            "SortBy": "",
            "SortFields": "",
            "ReportTitle": "",
            "Summary": false,
            "Filter1": "",
            "Filter2": "",
            "Filter3": "",
            "Filter4": "",
            "Filter5": "",
            "Filter6": "",
            "Filter7": "",
            "Filter8": "",
            "Filter9": "",
            "Filter10": "",
            "UserID": "Manager",
            "Character01": "",
            "Character02": "",
            "Character03": "",
            "Character04": "",
            "Character05": "",
            "Check01": false,
            "Check02": false,
            "Check03": false,
            "Check04": false,
            "Check05": false,
            "Number01": 0,
            "Number02": 0,
            "Number03": 0,
            "Number04": 0,
            "Number05": 0,
            "BAQRptID": "",
            "ReportID": "PackingListRpt",
            "Option01": "HKSH000019-20240722",
            "Option02": "",
            "Option03": "",
            "Option04": "",
            "Option05": "",
            "Option06": "",
            "Option07": "",
            "Option08": "",
            "Option09": "",
            "Option10": "",
            "Check06": false,
            "Check07": false,
            "Check08": false,
            "Check09": false,
            "Check10": false,
            "Date01": null,
            "Date02": null,
            "Date03": null,
            "Date04": null,
            "Date05": null,
            "Date01Token": "",
            "Date02Token": "",
            "Date03Token": "",
            "Date04Token": "",
            "Date05Token": "",
            "SysRowID": "00000000-0000-0000-0000-000000000000",
            "AutoAction": "SSRSPREVIEW",
            "PrinterName": "",
            "AgentSchedNum": 0,
            "AgentID": "",
            "AgentTaskNum": 0,
            "RecurringTask": false,
            "RptPageSettings": "",
            "RptPrinterSettings": "",
            "RptVersion": "",
            "ReportStyleNum": 1,
            "WorkstationID": "Manager",
            "TaskNote": "",
            "ArchiveCode": 0,
            "DateFormat": "m/d/yyyy",
            "NumericFormat": ",.",
            "AgentCompareString": "",
            "ProcessID": "",
            "ProcessCompany": "",
            "ProcessSystemCode": "",
            "ProcessTaskNum": 0,
            "DecimalsGeneral": 0,
            "DecimalsCost": 0,
            "DecimalsPrice": 0,
            "GlbDecimalsGeneral": 0,
            "GlbDecimalsCost": 0,
            "GlbDecimalsPrice": 0,
            "FaxSubject": "",
            "FaxTo": "",
            "FaxNumber": "",
            "EMailTo": "",
            "EMailCC": "",
            "EMailBCC": "",
            "EMailBody": "",
            "AttachmentType": "",
            "ReportCurrencyCode": "USD",
            "ReportCultureCode": "en-US",
            "SSRSRenderFormat": "PDF",
            "UIXml": "",
            "PrintReportParameters": false,
            "SSRSEnableRouting": false,
            "DesignMode": false,
            "RowMod": "A",
            "SpecifiedProperties": "AIAAAAMAAAgwAwDgEA==",
            "UserDefinedColumns": {}
        }
    ],
    "ReportStyle": [
        {
            "ColumnNames": 0,
            "Company": "XXXX",
            "ReportID": "PackingListRpt",
            "StyleNum": 1,
            "StyleDescription": "Standard - SSRS",
            "RptTypeID": "SSRS",
            "PrintProgram": "reports/CustomReports/PackingListRpt",
            "PrintProgramOptions": "",
            "RptDefID": "PackingListRpt",
            "CompanyList": "XXXX",
            "ServerNum": 0,
            "OutputLocation": "Database",
            "OutputEDI": "",
            "SystemFlag": false,
            "CGCCode": "",
            "SysRevID": 0,
            "SysRowID": "40d8e73e-a954-4df4-997f-def5095e4e7d",
            "RptCriteriaSetID": null,
            "RptStructuredOutputDefID": null,
            "StructuredOutputEnabled": false,
            "RequireSubmissionID": false,
            "AllowResetAfterSubmit": false,
            "CertificateID": null,
            "LangNameID": "",
            "FormatCulture": "",
            "StructuredOutputCertificateID": null,
            "StructuredOutputAlgorithm": null,
            "StatusCode": -2,
            "StatusDesc": "",
            "HasBAQOrEI": false,
            "RoutingRuleEnabled": false,
            "CertificateIsAllComp": false,
            "CertificateIsSystem": false,
            "CertExpiration": null,
            "Status": 0,
            "StatusMessage": "",
            "RptDefSystemFlag": false,
            "LangNameIDDescription": "",
            "IsBAQReport": false,
            "StructuredOutputCertificateIsAllComp": false,
            "StructuredOutputCertificateIsSystem": false,
            "StructuredOutputCertificateExpirationDate": null,
            "AllowGenerateEDI": false,
            "BitFlag": 0,
            "ReportRptDescription": "",
            "RptDefRptDescription": "",
            "RptTypeRptTypeDescription": "",
            "RowMod": "",
            "SpecifiedProperties": "////DwAA",
            "UserDefinedColumns": {}
        }
    ],
    "ExtensionTables": []
}

1 Like

Go and grab us the json from Epicor when the report is submitted.

2 Likes

Thanks

Any update on this? I’m running into the same issue, trying to generate a BAQ report via function. I’ve created C# code to convert the tableset I get back from the Get BAQ Report Params method into a dataset, in order to pass the dataset as an input param to TransformAndSubmit method, but continue to get a 400 error response for invalid dataset. When I view the created DS prior to the TransformAndSubmit method, it looks fine to me, something seems to go awry when I attempt to use it as an input param for T&S method.