How to use JavaScript to concat child records into a single field?
I'm trying to learn how to concatenate multiple child records into a single field on a report. I have spent a lot of time searching google and the help forums and have come up with nothing. I don't want to use reverse look up because there could be a lot of records I'm returning or only 1. I figured the best way to accomplish this would be JavaScript. Maybe some tutorials on how to implement JavaScript functionality with QuickBase would help.
UPDATED NEW AND IMPROVED: I have updated this example with more generic code where all the parameters are floated to the top and a template is used to define how to summarize child records to the parent field in the report (and I am not through refactoring yet):
//parameters: var dbid = "bkgzxdr4x"; var dbidParents = "bkgzxdr6t"; var dbidChilds = "bkgzxfptb"; var apptoken = "q2aznmd9h7eymbwavpzjbsc8hcf"; var n = 100; var relatedParentFid = "7"; var relatedParentLabel = "related_parent"; var clist = "3.7.10"; var qbuClass = "QBU_Childs"; var template = "<ul>{{#.}}<li>{{comment}}</li>{{/.}}</ul>";
This code does exactly what I need, I created a code page called concatenate.js but I do not know how to call it within the application, in the demo the data appeared in a field called childs is this done with the image onload technique? or am I missing something really obvious.
Trying to implement and can get an alert to show up, but not the concat code to show up. I updated all variables. I didn't put in underscores in field names since I don't use them. I changed field FIDs to 3.6.9. But can't get anything to load. Any help?
clist simply represents the column list and these all fields are from the child table I guess.
3 normally represents the Record ID# in every table, 7 is the related parent fid that you can replace based on your table and 10 is the field Id of that field which you want to include in the results.
Any ideas on how to make the concatenated value exportable? When I export to CSV, I'm seeing the content of the IOL field, rather than the concatenated child values.
The original example "Concatenate Children To Parent" performed the concatenation client-side (ie in your browser) as opposed to formula fields which are evaluated server-side. So while the example tossed the concatenated values into a cell of the table report and appear next to normal fields they have a different origin and you should not expect the concatenated values to export or print.
To get the export functionality what you would need to do is modify the script to generate a blob of CSV and download it through script. Here is what I think was the original post that introduced the idea of downloading "all the things" (ie anything):.
Several of the Pasites use this short download() function which you can use to force a file downlolad by specifying the filename and contenxt:
function download(filename, content) { var blob = new Blob([content]); var a = document.createElement("a"); a.href = window.URL.createObjectURL(blob); a.download = filename; a.style.display = "none"; document.body.appendChild(a); a.click(); } download("mydata.csv", "a,b,c\n1,2,3\n4,5,6");
To try it out just past the above code into your console.
If it isn't abundantly clear from similar file related questions in the forum, you can create parse, and manipulate files "out of thin air" - you don't need to start with a file attachment field or an actual file on your hard drive. Just "conjure" your needed file into existence using the Blob() constructor or other similar JavaScript affordances.
Hi Dan, or whoever else can help. I've been trying to get this to work and all I'm getting are the listed dots. So it's giving me the correct total number of dots for the exact total number of records but it is not returning the field values. Any suggestions on what we could be doing wrong?
To answer your question (and Vivek's below), the parameter that needs to be modified is actually here:
var template = "<ul>{{#.}}<li>{{comment}}</li>{{/.}}</ul>";
You'll want to change "comment" to the Field Label of the target field in your child table. You'll notice in the demo that Dan is querying for values in a field called "Comment"
And for those asking: yes, you need to write your field labels in lower case with underscores instead of spaces.
I have no idea why you mean by "dots". Since this question is two years old please post a new questions with just the relevant details that pertain to your issue.