Forum Discussion
WilliamMarrone
8 years agoQrew Cadet
That correctly returned the three records, is there any way to attach this to a Button to run from a homepage?
- _anomDiebolt_8 years agoQrew EliteEmbed a report on the homepage and within the report create a button field. QuickBase makes it difficult to attach a script to a lone button within the button bar.
- WilliamMarrone8 years agoQrew CadetThanks a lot is there any way to return the tuition as a number or convert it to summarize?
- _anomDiebolt_8 years agoQrew Elite> ... return the tuition as a number
tuition = parseFloat($("tuition", this).text());
> ... or convert it to summarize
Based on the names of your other fields (name and major) I would have assumed the record represented a person in the aggregate and that tuition would represent the current semester's tuition. If you need to summarize tuition you need to further describe your records and any child records along with how you want tuition to summarize (total, average, harmonic mean?) - WilliamMarrone8 years agoQrew CadetThank you and yes that all makes sense. This student work is just a test app I am using to avoid using our live data in case something goes ary. The end goal and you could tell me if this is viable or not, we want to create a script to write data from a few different apps to get year to date totals of sales numbers. I don't know how much functionality Quickbase has when it comes to injecting code and if this is possible,
- _anomDiebolt_8 years agoQrew Elite> ... how much functionality Quickbase has when it comes to injecting code ...
Once you get to script you exceed the functionality of QuickBase and anything is possible.
If you write your code like this you will return JSON instead of XML and you will not have to process each record with $().each(...):(function() {
var dbid = "<your application dbid>";
var dbidTable = "bm9rx6w83";
var apptoken = "tvy5zcdaqafyfxp43vhd78gyys";
$.ajaxSetup({data: {apptoken: apptoken}});
var XMLFlatToObj = function(xml, type) {
var data = [];
var record = {};
$("record", xml).each(function() {
record = {};
$(this).children().each(function () {
record[$(this).prop("tagName")] = $(this).text();
});
data.push(record);
});
return {records: data};
}
var promise = $.ajax({
url: dbidTable,
data: {
act: "API_DoQuery",
query: "{20.GT.1000}",
clist: "a",
options: "sortorder-D"
},
dataFilter: XMLFlatToObj
});
var promise = $.post(dbidTable, {
act: "API_DoQuery",
query: "{20.GT.1000}",
clist: "a",
options: "sortorder-D"
})
promise.then(function(response) {
console.log(JSON.stringify(response, null, " "));
});
})();
To gather JSON from multiple AJAX calls you simply create additional promises and with a $.when(promise1, promise2, promise3 ...) call you can merge the individual JSON responses together into one overall JSON structure using $.extend(). The combined JSON can be then summarized using underscore's _.groupBy() method and templated to HTML using underscore's _.template() method. - WilliamMarrone8 years agoQrew CadetDoes the Quickbase API have support for JSON objects and creating reports from them at all? Or would that require a bit of work around?
- _anomDiebolt_8 years agoQrew EliteThe API does not return JSON so one solution is to use the code I provided which converts the XML to JSON using the data filter option and the helper utility XMLFlatToObj. BTW, I just noticed a typo in the code - depth the second "var promise =" statement - I am on a tablet tonight and forgot to remove it.