Forum Discussion
Formula Extraction Script
I have a project underway that will allow QuickBase formulas to be converted to JavaScript. The project involves writing a grammar for QuickBase's formula language and parsing them using the parser library PEGjs (https://pegjs.org/). The grammar is written and I am now moving on to other aspects of the project which includes a massive amount of testing using a formal test framework. I need to test both valid and invalid formulas written with best practices as well as sloppily written formulas. I need thousands of formulas from a variety of sources for my testing.
You can assist my efforts if you wish by running a short script that will extract all the formulas from your application and after review send them to me as a CSV file. I do not need any table data for my testing or knowledge of your field types � all I need is the raw formula as entered into the textarea of the field definition page.
If you have formulas that are not confidential and wish to help my efforts please follow the five step procedure listed on the following pages.
Thanks for your assistance.
Step 1
Temporarily turn off application tokens for your script:
Step 2
Press F12 to expose the Developer Tools and click on the console tab. The Developer Tools may appear at the bottom, side or in a seperate window depending on the state you left it in on after a prior usage.
Step 3
Paste the following code into the console, press enter and wait for an �all done� message to be displayed.
var csv = "";
var subdomain = document.location.host.split(".")[0];
$.ajaxSetup({async: false});
var dbids = Object.keys(gTableInfo);
dbids.forEach(function(dbid) {
$.get(dbid, {
act: "API_GetSchema"
}).then(function(xml) {
$("fields field[mode=virtual]", xml).each(function(index, field) {
var fid = $(field).attr("id");
$("formula", field).filter(":not(:empty)").each(function(index, field) {
var formula = $(field).text();
csv += '"Client","${subdomain}","${dbid}","${fid}","${formula.replace(/"/g, '""')}"\n';
});
});
});
});
$("<textarea>").css({width: "100%", height: "300"}).html(csv).prependTo("body");
console.log("all done");
Here is what should appear in the console after you paste your code:
Step 4
When the script completes it will splice a textarea at the top of the page with all formulas listed in a blob of csv data. After review, copy this CSV data into a file, save it and email it to me as a file attachment.
My sample data csv contains four simple numeric formulas although your formulas will probably be much longer and slightly more difficult to recognize as CSV data.
"Client","haversineconsulting","bmqfp5qif","9"," + "
"Client","haversineconsulting","bmqfp5qif","10"," + +" + *
"Client","haversineconsulting","bmqfp5qif","11","" * * "
"Client","haversineconsulting","bmqfp5qif","12","
The fields in this CSV format are:
- Source
- Subdomain
- DBID
- FID
- Formula
Turn application tokens back on!
Even if you choose to not share your formulas I think you will find this exercise useful to review your own formulas. You can import the CSV data you generate into your own table and then review your accumulated formulas. Normally formulas are worked on in isolation one at a time. When you view your formulas en masse you can recognize obvious patterns that will allow you to improve your formula's readability and identify reusable patterns. When you review thousands of formulas as I am doing you get enormous insights into the formula language and best practices as well as pave the way for the replacement supplementation of the formula language with JavaScript.