Hello there!
I am trying to put data from bigquery response API, into a table to create record types.
So far, I have been able to get the response from bigquery and convert it to appian values, the response looks like this:
then, I created a rule to narrow down to the values, but as you can see, the column name does not come from the response, so it displays all the values as rows but on the following way :
so as you see, I do not have columns there , I guess the best way to go on this, will be to get the JSON response converted to an array, and then pass it to a table but not sure if this is possible, any advise?
Discussion posts and replies are publicly visible
Do the column names come back somewhere else in the API response, or are you just expected to know them?
Either way I suspect you'll have to loop over the response rows and manually construct the necessary dictionary from each row's results. If each row will always have the exact same number of columns and you can just hardcode the column/property names, then this should be pretty easy. If there's an expectation that the columns might be variable and/or will need to be named after data that's given in another part of the response, then it's still doable but might be a bit harder.
Hello, thanks for your response.
From this response from bigQuery no, the column names do not come in the response anywhere, for that, you need to do another request on a different API from bigquery.
I get what you are saying of doing a loop, however, I have not found a way to create a table or a way to use loops, is it like on the interfaces or somewhere on the design pane?
Thanks a lot Mike, sure thing, here is the requested information:
{{f: {{v: "Cali"}, {v: "country"}, {v: "AA"}, {v: "1/22/2021 11:47"}, {v: "5/11/2021 13:33"}, {v: "Match Sent"}, {v: "ZR_11607_CAND"}, {v: "5.09e+17"}, {v: "source"}}},
{f: {{v: "name"}, {v: "country"}, {v: "AA"}, {v: "3/22/2021 15:51"}, {v: "5/11/2021 13:16"}, {v: "Pending"}, {v: "ZR_12952_CAND"}, {v: "5.09e+17"}, {v: "source"}}}
{f: {{v: "name"}, {v: "country"}, {v: "AA"}, {v: "3/8/2021 11:20"}, {v: "5/11/2021 13:18"}, {v: "Proposed"}, {v: "ZR_13933_CAND"}, {v: "5.09e+17"}, {v: "source"}}}
I am working on using a data type, I was able to show now the correct column names, now I am just trying to figure out how the foreach syntax works in Appian (I'm new here) so maybe that will do it too
I believe it would end up being something along these lines, plus or minus:
a!forEach( rule!bigQuery().result.body.rows, createDictionary( {"State", "Country", ...}, /* array of all column/property names */ fv!item.v ) )
Thanks Mike,
I tried this code
a!forEach( rule!TGSU_bigquery().result.body.rows,
createdictionary({"Duckling", "Country", "Job Type","History created time", "Last activity time", "status","candidate_id","candidateID","source"}, /* array of all column/property names */ fv!item.v))
but it returns an error saying ' Expression evaluation error at function a!forEach: Error in a!forEach() expression during iteration 1: Expression evaluation error at function 'createdictionary' [line 4]: The list of keys and values must be of the same length. Recieved 9 keys and 1 values.'
then I guess is because I only added an 'fv!item.v' but if I add more, then I still get an error saying unexpected number of parameters
Please try running just this much, and seeing what the output is / what it's formatted like:
a!forEach( rule!TGSU_bigquery().result.body.rows, fv!item)
It returns the same thing as the response from the API from bigquery
I tried creating a type data, like a CDT and it shows this on a grid
however, to loop into it, do I use something like
'type!{urn:com:appian:types:TGSU}TGSU_tabletest'(),
I tried to use the code above but may have syntax errors, but not sure if I'm on the right way?
how about "rule!TGSU_bigquery().result.body.rows.f"?
I tried that, butt it returns the values on 'v:' I showed before :( is there a way to get a tutorial or something on converting JSON to array or to values to put into a table?
rodrigoe0001 said:butt it returns the values on 'v:' I showed before
I expected this, I was just curious to see the overall shape of the data when it's called that way.
What i'm hunting for here is how exactly we can refer to the dictionary value within your a!forEach() loop and effectively grab the array of deepest "v:" values, a group at a time, to convert to the dicitonary.
Yeah, that is exactly what we need, I am doing some testing now but I think this may not be possible as I'm encountering a lot of limitations, probably I will need to workaround it , please let me know if you find a way on doing that.
Try these permutations, just in case, and see if either happens to work any better:
first:
a!forEach( rule!bigQuery().result.body.rows.f, /* adding ".f" at the end here */ createDictionary( {"State", "Country", ...}, /* array of all column/property names */ fv!item.v ) )
Second, somewhat more radical:
a!forEach( rule!bigQuery().result.body.rows.f, createDictionary( {"State", "Country", ...}, /* array of all column/property names */ a!forEach( /* create an inner forEach loop, attempt to loop over the inner array of dictionaries containing the "v:" property */ fv!item, fv!item.v ) ) )
Awesome!!! The first option worked and I now have all records tied to a key
My question is now, how do I then attach this records into a table? Do I have to create it as record type?
Cool, I knew it was something like that.
So from here what you do depends on what your intended end result is. If your aim is to store the data exactly in a DB table, then in general my first step would be to create a DB table with the columns you need, then use the CDT creator in Appian (i.e. create CDT based on existing DB table). Then you would be able to use the above logic i.e. in an expression rule called in a process node, save it to a multiple-PV set as your new CDT type, then pass that into a WTDS node.
Got it,
What I need is to simply display that response as a table on a site, do I still need to create a db for that?
On the tutorials, there is a SpaceX app that gets created based on an API response, I want something similar to that, where I get records from the API and I display that on a table
rodrigoe0001 said:What I need is to simply display that response as a table on a site, do I still need to create a db for that?
That depends mainly on whether you need to store the responses for some time, or whether it will be sufficient to call the API on-demand (and every time the user loads that form). Assuming you end up with an expression rule that returns a tidy dictionary of data though, you can simply feed that into the data parameter of the Read-Only Grid and use that live, without having to store it or retrieve it from a DB table.
Yeah, I want only on-demand pretty much, the API is calling the data I need already.
Alright so I guess I just need to figure out the expression to show that data
Thanks a lot Mike!
Assuming your expression rule now outputs an array of dictionaries with proper column names, try just setting that as the "Data" parameter of your read-only grid. After a few other fairly easy configuration items, you should be ready to go.