February 7, 201411 yr I am trying to create a calculated field in FileMaker 11 that contains javascript code. I have a database with a parent table "Slides" and a child table "Images". I have created a calculated field called "all_info" in the Slides table that formats all the fields into a large text field. But I am having problems trying to get the formatting correct when there is more than one child record... Example: Slide 00001 has two related records in the "Images" table. The Images table has a field "filename". Slide 00001 has related records with "imageA.jpg" and "imageB.jpg". Result I am looking for (in my "all_info" calculated field): filename[0] = "imageA.jpg"; filename[1] = "imageB.jpg"; I believe I need to use the List function to get a return-delimited list of both images, but I don't know how to format the results (getting it to add the "0", "1", etc) I tried doing a variety of searches to find this answer, but could not come up with a match... Thanks, Brian
February 8, 201411 yr Try the attached file, and make sure to read the comment in the calculation; you get recursion without a Custom Function, but the method is a bit hackish … (I think). Also, I'm no JavaScript expert, but you could probably pass the result of List() unmodified and have it processed there. PS: Please update your profile. CreateNumberedArray_eos.fp7.zip
February 10, 201411 yr the method is a bit hackish … (I think). Yes it is. Filemaker has a mechanism for performing recursive calculations through custom functions. This mechanism has built-in protections against runaway calculations. Such protections are not present in a regular calculation field, and you run the risk of crashing your file.
February 10, 201411 yr Author Thank you eos! I had to tweak it a little, but it is doing exactly what I needed!! As for the comment about Custom Functions, can I take what eos had and (simply) put that in as a custom function? Brian
February 10, 201411 yr If you are able to use a custom function (contrary to what your profile shows!) I'd suggest you do the conservative thing and refrain from using a $variable which runs a risk of collision - unless managed carefully at the file level. For example, try: NumberedList ( listOfValues ) = Let ( [ n = ValueCount ( listOfValues ) ; item = GetValue ( listOfValues ; n ) ; pattern = "filename[#] = "item";" ] ; Case ( n > 1 ; NumberedList ( LeftValues ( listOfValues ; n - 1 ) ) & ¶ ) & Case ( n ; Substitute ( pattern ; [ "#" ; n - 1 ] ; [ "item" ; item ] ) ) ) This would be called from a calculation field (result is Text) in the parent table in the form of = NumberedList ( List ( Child::Valuefield ) )
February 10, 201411 yr Author Thank you. I will look into that... (Yes, I use FM Pro 11 for most things, but have access to Advanced if needed - like in this case) Brian
Create an account or sign in to comment