Forum Discussion
AustinK
6 years agoQrew Commander
Honestly if you want help with something like that you are going to have to provide more detail. If it is something that is that integral to your app then chances are someone else isn't going to be able to just pop it into a page and start testing.
What troubleshooting have you done so far?
Where do you think the issue in the code is?
Can you narrow it down at all?
Your js file name has tablet in it, is this for mobile only? More things someone would need to know.
This is a good lesson in being careful with where you use JavaScript. I have it in many places in my app but I do not rely on it for something that would make the business grind to a halt if it suddenly stopped functioning. There is always another way to get the work done easily just not as nice as whatever JavaScript feature I may add. Many reasons for this but the main reason is QuickBase does not support the use of JavaScript like this and they honestly seem very against it whenever an employee posts, so using it is at your own risk.
What troubleshooting have you done so far?
Where do you think the issue in the code is?
Can you narrow it down at all?
Your js file name has tablet in it, is this for mobile only? More things someone would need to know.
This is a good lesson in being careful with where you use JavaScript. I have it in many places in my app but I do not rely on it for something that would make the business grind to a halt if it suddenly stopped functioning. There is always another way to get the work done easily just not as nice as whatever JavaScript feature I may add. Many reasons for this but the main reason is QuickBase does not support the use of JavaScript like this and they honestly seem very against it whenever an employee posts, so using it is at your own risk.
DEVICECYCLE
6 years agoQrew Member
We have 3 .js pages like these that uses the a "Button Formula" like this:
"<a class=\"Vibrant Success\" onclick=\"$.getScript(gReqAppDBID+'?a=dbpage^pagename=" & "Tabletmodulev43.js"& "');return false;\">" &"FINALIZE"& "</a>"
The function of the page "Tabletmodulev43.js" is to import a summary of one table to another table by logging it first to console log and creating an XML object then importing it to a table:
We did this because Quickbase only does table to table import and doesn't have this feature.
What we are really needed is TableSummary to Table import.
Let me know if there some other way to do this other than Javascript.
(function() {
var XMLStructuredToObj = function(xml, type) {
var fidToLabel = {};
$("field", xml).each(function() {
var id = $(this).attr("id");
var label = $("label", this).text();
//console.log(id, label);
fidToLabel[id] = label;
});
var data = [];
var record = {};
$("record", xml).each(function() {
record = {};
$("f", this).each(function() {
record[fidToLabel[$(this).attr("id")]] = $(this).text();
});
data.push(record);
});
return {records: data};
};
var dbid = "bkuuybf9b";
var dbidAssetID = "bmuq9d5dj";
var dbidItemDetails = "bpb3hui78";
var apptoken ="t8gsgdut8g28cw2fw7fbek3vw9";
$.ajaxSetup({data: {apptoken: apptoken}});
$.ajax({
url: dbidAssetID,
data: {
act: "API_DoQuery",
query: "{33.EX._fid_19}",
clist: "23.6.19.29.31.30.26",
slist: "23.6.19.29.31.30.26",
fmt: "structured"
},
dataFilter: XMLStructuredToObj
}).then(function(json) {
console.dir(json);
var groups = _.groupBy(json.records, function(record) {
return record["Related Model Numbers"] + "|" + record["V43 - Tier"] + "|" +record["Related Purchase Order / Service Program"] + "|" +record["Asset ID - Item Detail - Related Manufacturer"]+ "|" +record["Asset ID - Item Detail - Related PN ID"]+ "|" +record["Asset ID - Item Detail - Type"]+ "|" +record["Tablet Triage Summary ID"];
});
var csv = _.map(groups, function(item, key) {
return '"' + (key + "|" + item.length).split("|").join('","') + '"';
});
console.log(csv.join("\n"));
$.post(dbidItemDetails, {
act: "API_ImportFromCSV",
clist: "6.7.8.9.10.11.12.13",
records_csv: csv.join("\n")
}).then(function(xml) {
console.dirxml(xml);
document.location.
Thank you,
------------------------------
Roel David
------------------------------
"<a class=\"Vibrant Success\" onclick=\"$.getScript(gReqAppDBID+'?a=dbpage^pagename=" & "Tabletmodulev43.js"& "');return false;\">" &"FINALIZE"& "</a>"
The function of the page "Tabletmodulev43.js" is to import a summary of one table to another table by logging it first to console log and creating an XML object then importing it to a table:
We did this because Quickbase only does table to table import and doesn't have this feature.
What we are really needed is TableSummary to Table import.
Let me know if there some other way to do this other than Javascript.
(function() {
var XMLStructuredToObj = function(xml, type) {
var fidToLabel = {};
$("field", xml).each(function() {
var id = $(this).attr("id");
var label = $("label", this).text();
//console.log(id, label);
fidToLabel[id] = label;
});
var data = [];
var record = {};
$("record", xml).each(function() {
record = {};
$("f", this).each(function() {
record[fidToLabel[$(this).attr("id")]] = $(this).text();
});
data.push(record);
});
return {records: data};
};
var dbid = "bkuuybf9b";
var dbidAssetID = "bmuq9d5dj";
var dbidItemDetails = "bpb3hui78";
var apptoken ="t8gsgdut8g28cw2fw7fbek3vw9";
$.ajaxSetup({data: {apptoken: apptoken}});
$.ajax({
url: dbidAssetID,
data: {
act: "API_DoQuery",
query: "{33.EX._fid_19}",
clist: "23.6.19.29.31.30.26",
slist: "23.6.19.29.31.30.26",
fmt: "structured"
},
dataFilter: XMLStructuredToObj
}).then(function(json) {
console.dir(json);
var groups = _.groupBy(json.records, function(record) {
return record["Related Model Numbers"] + "|" + record["V43 - Tier"] + "|" +record["Related Purchase Order / Service Program"] + "|" +record["Asset ID - Item Detail - Related Manufacturer"]+ "|" +record["Asset ID - Item Detail - Related PN ID"]+ "|" +record["Asset ID - Item Detail - Type"]+ "|" +record["Tablet Triage Summary ID"];
});
var csv = _.map(groups, function(item, key) {
return '"' + (key + "|" + item.length).split("|").join('","') + '"';
});
console.log(csv.join("\n"));
$.post(dbidItemDetails, {
act: "API_ImportFromCSV",
clist: "6.7.8.9.10.11.12.13",
records_csv: csv.join("\n")
}).then(function(xml) {
console.dirxml(xml);
document.location.
Thank you,
------------------------------
Roel David
------------------------------
- AustinK6 years agoQrew CommanderThat is interesting. So you need a copy of the tables field names with their ID's to get imported to another table? I see some more happening there but it's a little tough to visualize what it is doing for me right now. I'm hoping to get some helpful info from you so I can mull it over and hopefully others are able to jump in too.
Which part is currently failing? Is any error happening or does it just not work? Even a console error.- DEVICECYCLE6 years agoQrew Memberthe console only says "null" but in debugging it highlighted "console.dir(json);".
By the way, this is the illustration of what this js. does for us in a smaller scale, just disregard the field name
Table 1 (this is the source table)
Letter Number Color shapes Qty a 1 black circle 1 b 2 white yellow square 1 c 1 green circle 1 d 2 green square 1 a 1 orange square 1 b 2 black square 1 c 1 white yellow square 1 d 2 green square 1 a 1 green square 1 b 2 orange square 1 c 1 black circle 1 d 2 white yellow circle 1 a 1 green square 1 b 2 green triangle 1 c 1 orange circle 1 d 2 green circle 1
It groups it by variation and summarize it into xml, (notice the variation a-1-green-square has total quantity of 2)
Letter Number Color shapes Total Qty a 1 black circle 1 a 1 green square 2 a 1 orange square 1 b 2 black square 1 b 2 green triangle 1 b 2 orange square 1 b 2 white yellow square 1 c 1 black circle 1 c 1 green circle 1 c 1 orange circle 1 c 1 white yellow square 1 d 2 green circle 1 d 2 green square 2 d 2 white yellow circle 1
Then it imports it to Table no2 - here should be the result of the destination table.
Letter Number Color shapes Total Qty a 1 black circle 1 a 1 green square 2 a 1 orange square 1 b 2 black square 1 b 2 green triangle 1 b 2 orange square 1 b 2 white yellow square 1 c 1 black circle 1 c 1 green circle 1 c 1 orange circle 1 c 1 white yellow square 1 d 2 green circle 1 d 2 green square 2 d 2 white yellow circle 1
Please let us know if there's any other way to accomplish this.
We really appreciates your help,
Roel
------------------------------
Roel David
------------------------------- MarkShnier__You6 years ago
Qrew Legend
If this is mission critical, I would suggest contacting one of the larger the QSP shops who have JavaScript coders on staff. Trinity, Veil Sun, MCF, The Data Collaborative, CloudBase come to mind, among others.
------------------------------
Mark Shnier (YQC)
Quick Base Solution Provider
Your Quick Base Coach
http://QuickBaseCoach.com
markshnier2@gmail.com
------------------------------