Episode 1 → DataSet Manipulation
As an offshoot of this thread:
As well as this idea: Allow System.Object to be used in BPMs and Functions
I bring you a little fun in case you need it.
In that thread I mentioned:
So, let’s explain this a bit further.
Say you have this super custom object, and you want to return it without serializing it into a string.
You can’t directly using normal means. Hopefully that will change, go vote please.
You can however return a DataSet… and a DataSet can contain a column type of “System.Object”, which means, if you return a row, with a serializable object, then guess what… you have a custom return type.
You will have to select the table, and the row, but it’s sure better than nothing!
Ok, on to the example:
Code:
//Our output variable "output" is defined as a System.DataSet
output = new DataSet(); //Initialize
var dataTable = new DataTable("YourTableName"); //Add a table
var dataColumn = new DataColumn("YourColumnName", typeof(object)); //Add a column of type "object"
dataTable.Columns.Add(dataColumn); //Add the column to the table
output.Tables.Add(dataTable); //Add the table to the dataset
//Example of custom object return
//Make some BS Data lol ->
//Month Numbers Dictionary
var monthInts = Enumerable.Range(1, 12).ToList();
var dicMonths = new Dictionary<string, int>();
monthInts.ForEach(x => {dicMonths.Add(System.Globalization.DateTimeFormatInfo.CurrentInfo.GetMonthName(x), x);});
//Our custom object
var ourCustomObject = new
{
Hello = "World!", //Of course
EatItLyrics = new [] //An array
{
"How come you're always such a fussy young man?",
"Don't want no Captain Crunch, don't want no Raisin Bran",
"Well, don't you know that other kids are starving in Japan?",
"So, eat it, just eat it"
},
MonthsAsDictionary = dicMonths, //A Dictionary
ABC = Db.ABCCode.Take(2).ToList(), //Some Db Rows
};
//Add our custom object as a row to the table in the dataset
dataTable.Rows.Add(ourCustomObject);
//Enjoy
Output
{
"YourTableName": [
{
"YourColumnName": {
"Hello": "World!",
"EatItLyrics": [
"How come you're always such a fussy young man?",
"Don't want no Captain Crunch, don't want no Raisin Bran",
"Well, don't you know that other kids are starving in Japan?",
"So, eat it, just eat it"
],
"MonthsAsDictionary": {
"January": 1,
"February": 2,
"March": 3,
"April": 4,
"May": 5,
"June": 6,
"July": 7,
"August": 8,
"September": 9,
"October": 10,
"November": 11,
"December": 12
},
"ABC": [
{
"$id": "1",
"Company": "000000",
"ABCCode1": "A",
"CountFreq": 30,
"ExcludeFromCC": false,
"StockValPcnt": 0,
"PcntTolerance": 0,
"CalcPcnt": false,
"CalcQty": false,
"CalcValue": false,
"QtyTolerance": 0,
"ValueTolerance": 0,
"ShipToCustNum": 0,
"SysRevID": "AAAAAAi6GeQ=",
"SysRowID": "acbcb805-9d15-fca7-e311-33e0dbc8c227",
"EntityKey": {
"$id": "2",
"EntitySetName": "ABCCode",
"EntityContainerName": "ErpContext",
"EntityKeyValues": [
{
"Key": "SysRowID",
"Value": "acbcb805-9d15-fca7-e311-33e0dbc8c227"
}
]
}
},
{
"$id": "3",
"Company": "000000",
"ABCCode1": "B",
"CountFreq": 30,
"ExcludeFromCC": false,
"StockValPcnt": 0,
"PcntTolerance": 0,
"CalcPcnt": false,
"CalcQty": false,
"CalcValue": false,
"QtyTolerance": 0,
"ValueTolerance": 0,
"ShipToCustNum": 0,
"SysRevID": "AAAAAAAagVU=",
"SysRowID": "acbcb805-9d15-fca7-e311-33e040fdc527",
"EntityKey": {
"$id": "4",
"EntitySetName": "ABCCode",
"EntityContainerName": "ErpContext",
"EntityKeyValues": [
{
"Key": "SysRowID",
"Value": "acbcb805-9d15-fca7-e311-33e040fdc527"
}
]
}
}
]
}
}
]
}
And there you have it.
Note:
Using a custom DataSet as an input will be more limiting because of the way Newtonsoft deserializes it. You might can still do some cool stuff, but it won’t be able to deserialize something this complex directly. We can discuss.