Skip to main content
Question

How to use JavaScript to concat child records into a single field?

  • December 16, 2015
  • 0 replies
  • 599 views

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.

This topic has been closed for replies.

  • Quickbase Alumni
  • December 24, 2015

  • Quickbase Alumni
  • December 29, 2015
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>";   


Concatenate Children To Parent ~ ListAll2
https://haversineconsulting.quickbase.com/db/bkgzxdr6t?a=q&qid=5

Pastie Database
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=464

More to come ...

  • Quickbase Alumni
  • January 19, 2016
Good Morning Everyone

At the risk of sounding silly I have a question

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.



Many thanks



paul

  • Quickbase Alumni
  • January 19, 2016
Yes it uses the IOL technique. To implement follow the link in the pastie for step by step instructions.

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?

  • Quickbase Alumni
  • August 16, 2017
working hard to implement this without luck yet...

Can anyone tell me what these fields are?
var clist = "3.7.10";

Is this from the child table?
var relatedParentFid = "7";

  • Quickbase Alumni
  • September 7, 2017
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.

Thanks!

  • Quickbase Alumni
  • September 7, 2017
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):.





Download All The Things
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=416

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.

  • Quickbase Alumni
  • October 5, 2017
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?

  • Quickbase Alumni
  • October 5, 2017
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.

HI,
I'm getting this text in the Childs field of the "Parents" table.




<img qbu='module' src='/i/clear2x2.gif' onload="javascript:if(typeof QBU=='undefined'){QBU={};$.getScript(gReqAppDBID+'?a=dbpage&pagename=module.js&rand='+new Date().getTime())};"><div class=QBU_Childs data-rid=1></div>


What is the thing that I missed. please Help. (I updated the Variables in the .js file )