Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Creating javascript array using a calculation

Featured Replies

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

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

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.

  • 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

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 ) )
  • 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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.