Jump to content
Server Maintenance This Week. ×

Creating javascript array using a calculation


This topic is 3733 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ) )
Link to comment
Share on other sites

This topic is 3733 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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