Chris.ro
(Chris )
March 18, 2025, 12:11pm
1
How can I initialize a DataTable with default-values for testing/debug as an in_argument in a workflow?
It must be something similar to:
New DataTable from { {“row1col1”, “r1c2”}, { “r2c1”, “r2c2” } }
How exactly should be the syntax please?
// please understand the question and don’t recommend activities as “Build DataTable” (as in other topics), cause when the workflow is invoked, the in_datatable is already initialized. The need is just for quick testing and debug the xaml alone (independent of the rest of project)
ppr
(Peter Preuss)
March 18, 2025, 12:18pm
2
out of the box, there is no DataTable init statement, which populates also the values, as the data table needs a defined column structure
However, have a look at this JSON trick
1 Like
arivu96
(Arivazhagan A)
March 18, 2025, 12:19pm
3
Try this
New DataTable From {{"Column1", "Column2"}, {"row1col1", "r1c2"}, {"r2c1", "r2c2"}}
Regards,
Arivu
Chris.ro
(Chris )
March 18, 2025, 12:24pm
4
error BC36718: Cannot initialize the type ‘DataTable’ with a collection initializer because it is not a collection type
ppr
(Peter Preuss)
March 18, 2025, 12:28pm
5
we got this error as it is not supported, due to also mentioned:
Chris.ro
(Chris )
March 18, 2025, 12:30pm
6
thx, it looks interesting and could be a solution
JArray is not declared. What have I import for it?
please write the syntax as a text, instead of picture, so we can copy it to test it
arivu96
(Arivazhagan A)
March 18, 2025, 12:36pm
7
Hi @Chris.ro ,
NO LUCK
There is no single line code to create a datatable with default values.
You have to use build datatable/invoke code/ using multiple assign activity to achive.
or you can go with @ppr suggestion
Regards,
Arivu
Chris.ro
(Chris )
March 18, 2025, 12:41pm
8
thx arivu, I like also the ppr’ suggestion.
What do I need to use his “JArray”?
btw: the syntax could be also on more lines. Do you know how init on more lines?
ppr
(Peter Preuss)
March 18, 2025, 12:43pm
9
JArray.Parse("[{""col1"":""val1""},{""col1"":""val2""},{""col1"":""val2""}]").ToObject(Of DataTable)
2 Likes
ppr
(Peter Preuss)
March 18, 2025, 12:48pm
10
when lines are rows, then it is already done:
as we already can proof
When structure is about more columns, similiar we can use the JSON Trick:
JArray.Parse("[{""col1"":""valA1"",""col2"":""valB1""},{""col1"":""valA2"",""col2"":""valB2""}]").ToObject(Of DataTable)
3 Likes
system
(system)
Closed
March 21, 2025, 12:54pm
12
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.