How to build and stringify JSON data from a dataview for sending to a function?

Hey there,

I’ve tried a bunch of things and have failed to figure this thing out. Maybe that’s only the Friday talking.

This is from a customization layer on a Kinetic dashboard and BAQ results.

In a kinetic-function widget, I can pass along the contents of a dataview inside the method parameters field value to the string parameter inJson like this:

Field Value
{xxxProcessingDV}

I get a payload that looks like this:

{inJson: {,…}}
inJson
:
{,…}
xxxProcessingDV
:
[{Calculated_PropertyIssue: false, Calculated_Calculated_Stage: false,…},…]
0
:
{Calculated_PropertyIssue: false, Calculated_Stage: false,…}
Calculated_DynAttrColor
:
“CHRY”
Calculated_Calculated_DynAttrDOD

and so on.

I get an error passing that into the function, I’m guessing because it’s an object and not a string at this point

I’ve tried a number of variations on JSON.stringify() including something like this: JSON.stringify({xxxProcessingDV}) but get errors on that. I’ve tried stuffing this into TransView.SerializedData but the row-update fails.

There’s only three rows of data here, so I don’t think it’s a size thing.

It would be cool if I could just pass the dataview contents to a BAQ tableset parameter on the function side, but that’s just getting greedy, I think.

Anyone have an easy way to do this, or a hard way that works?

Thanks,

Joe

Aren’t the results a dataview? Just pass it to the function as a dataset then process it.

2 Likes

Here is an example
Created a BAQ and a dashboard, adding a button


Created an event for a button click

Setup the trigger

Setup the function request parameters

Added a message handler to display the output results in the function

Function Signature

Code snippet

//Create a list iterate through
var selectedLines = input.Tables["DV_BAQ_TestABC"].AsEnumerable()
    .Where(x => x.Field<bool?>("Calculated_IsSelected") == true)
    .Select(x => new 
    { 
        ABCCode = x.Field<string>("ABCCode_ABCCode"), 
        CountFreq = x.Field<double>("ABCCode_CountFreq"), 
    })
    .ToList();

I did use a selector in this example, although not necessary.  Interestingly attempting add a selector field to the columns seemed to break the execution of the baq in the dashboard, so ended up adding the Calculated_Selected field in the BAQ.





// Return the result
var formattedLines = selectedLines.Select(x => $"{x.ABCCode} / {x.CountFreq}");
var rowIdList = "Abc Code / Count Freq" + Environment.NewLine + string.Join(Environment.NewLine, formattedLines);
output = $"{rowIdList}{Environment.NewLine}";

This was done on 2025.2
Hope that helps.

6 Likes

Thanks, Hally!

1 Like

I’ve had success using:

#_JSON.stringify(trans.dataView('YourDataView').viewData)_#

Simon’s suggestion is a lot more straightforward, though!

1 Like

Cool, thanks.

1 Like