Invalid Dataset Error During Function API Call

A tale of two DataSets… or is it?

When is a DataSet not a DataSet ?

It looked like a duck, quacked like a duck, but alas, it was not a duck.

Well I wish I had just checked, as this would have been a clue to speed this along…
Here is the function signature for TransformAndSubmit

BAQReportSvcContract.TransformAndSubmit(object, string, long, int, string)

That first parameter is of type object. What kind of object? You’d be forgiven for thinking it’s a DataSet, since for all practical purposes, it is.

Well it’s not.

It’s pretty much a JObject / JToken. Pretty much the Newtonsoft representation of a DataSet, if you deserialized JSON directly without a type.

Here is the code that works with TransformAndSubmit

//TransformAndSubmit Example

//Send json serialized object to the system monitor through the error report mechanism..
//This will terminate the function btw
Action<object> ThrowJson = (o) =>
{
    throw new BLException(JsonConvert.SerializeObject(o));
};

string reportID = "smwh";
int reportStyleNum = 1;

CallService<Ice.Contracts.BAQReportSvcContract>(baqReportSvc =>
{
    Ice.Tablesets.BAQReportTableset baqReportTS = baqReportSvc.GetNewParametersForReportId(reportID);
    
    //ThrowJson(baqReportTS); //Debug
    
    var baqParams = baqReportTS.BAQReportParam.FirstOrDefault();

    baqParams.BAQID            = "smwh";    
    baqParams.UserID           = Session.UserID;
    baqParams.ReportID         = reportID; //Not needed, call to GetNewParametersForReportId takes care of it
    baqParams.AutoAction       = "SSRSPREVIEW";
    baqParams.WorkstationID    = $"web_{Session.UserID}";
    //baqParams.WorkstationID  = Session.TaskClientID; //You can use this too
    baqParams.ReportStyleNum   = reportStyleNum;
    baqParams.AttachmentType   = "PDF";
    baqParams.SSRSRenderFormat = "PDF";
    //baqParams.RowMod         = "A"; //Not needed, call to GetNewParametersForReportId takes care of it
    
    //ThrowJson(baqReportTS); //Debug

    //Does NOT work!
    //baqReportSvc.TransformAndSubmit(baqReportTS, "", 0, 0, $"Ice.UIRpt.{reportID}");

    //Does NOT work!
    //DataSet ds = Ice.DatasetAdapter.ConvertToGenericDataset(baqReportTS, "", null, true);
    //baqReportSvc.TransformAndSubmit(ds, "", 0, 0, $"Ice.UIRpt.{reportID}");

    //Works
    //DataSet ds = Ice.DatasetAdapter.ConvertToGenericDataset(baqReportTS, "", null, true);
    //string json1 = JsonConvert.SerializeObject(ds);
    //baqReportSvc.TransformAndSubmit(JsonConvert.DeserializeObject(json1), "", 0, 0, $"Ice.UIRpt.{reportID}");

    //Works
    //string json2 = JsonConvert.SerializeObject(baqReportTS);
    //baqReportSvc.TransformAndSubmit(JsonConvert.DeserializeObject(json2), "", 0, 0, $"Ice.UIRpt.{reportID}");

    //Works
    string json3 = JsonConvert.SerializeObject(baqReportTS);
    baqReportSvc.TransformAndSubmit(JToken.Parse(json3), "", 0, 0, $"Ice.UIRpt.{reportID}");

    //Works
    //string json4 = JsonConvert.SerializeObject(baqReportTS);
    //baqReportSvc.TransformAndSubmit(JsonConvert.DeserializeObject<dynamic>(json4), "", 0, 0, $"Ice.UIRpt.{reportID}");


    //Transform and submit is not taking a DataSet, it wants an object that "looks" and "feels" like a DataSet (It's a damn dataset lol!)
    //Function Signature -> BAQReportSvcContract.TransformAndSubmit(object, string, long, int, string)'
    //Object is "ds", but it is not a DataSet. This wants a JToken or something similar 
 
});

And as promised, the SubmitToAgent Example as well →

//SubmitToAgent Example

//Send json serialized object to the system monitor through the error report mechanism..
//This will terminate the function btw
Action<object> ThrowJson = (o) =>
{
    throw new BLException(JsonConvert.SerializeObject(o));
};


string reportID = "smwh";
int reportStyleNum = 1;

CallService<Ice.Contracts.BAQReportSvcContract>(baqReportSvc =>
{
    Ice.Tablesets.BAQReportTableset baqReportTS = baqReportSvc.GetNewParametersForReportId(reportID);
    
    //ThrowJson(baqReportTS); //Debug
    
    var baqParams = baqReportTS.BAQReportParam.FirstOrDefault();

    baqParams.BAQID            = "smwh";
    baqParams.UserID           = Session.UserID;
    baqParams.ReportID         = reportID; //Not needed, call to GetNewParametersForReportId takes care of it
    baqParams.AutoAction       = "SSRSPREVIEW";
    baqParams.WorkstationID    = $"web_{Session.UserID}";
    //baqParams.WorkstationID  = Session.TaskClientID; //You can use this too
    baqParams.ReportStyleNum   = reportStyleNum;
    baqParams.AttachmentType   = "PDF";
    baqParams.SSRSRenderFormat = "PDF";
    //baqParams.RowMod         = "A"; //Not needed, call to GetNewParametersForReportId takes care of it



    //Begin Write XML----------------------------------------------------------------------------------------------->
    var dynamicReportTableset = new Ice.Tablesets.DynamicReportTableset();
   
    CallService<Ice.Contracts.DynamicReportSvcContract>(dynamicCriteriaSvc=>
    {
       dynamicReportTableset = dynamicCriteriaSvc.GetByID(reportID);
    });
    
    var dynamicReportDataSet = Ice.DatasetAdapter.ConvertToGenericDataset(dynamicReportTableset, "", null, true);

    StringWriter writer = new StringWriter();
    dynamicReportDataSet.WriteXml(writer);

    baqParams.Filter1 = writer.ToString();
    //-------------------------------------------------------------------------------------------------End Write XML>
    

    //ThrowJson(baqReportTS); //Debug
    
    baqReportSvc.SubmitToAgent(baqReportTS, "", 0, 0, $"Ice.UIRpt.{reportID}");

});

Files →
PrintBAQReportExample1.efxb (6.3 KB)
PrintBAQReportExample1.efxj.txt (6.8 KB) ← Remove .txt

3 Likes