Jump to content

GetNthRecord and Repeating Fields in Custom Functions


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

Recommended Posts

In a related topic (Multiplying Fields Together) a solution to the problem of multiplying together a set of fields (in separate records) was given:

Product (fieldname; n_records) = If (n_records>1; GetNthRecord(fieldname; n_records)*Product(fieldname; n_records-1); GetNthRecord(fieldname; n_records) )

Now suppose that fieldname is a repeating field. My testing seems to indicate that this custom function only works for the first repetition. I found that surprising (I am learning to not be surprised by FileMaker), but I can't seem to figure out why it is not working. Based on the documentation for GetNthRecord it seems the syntax for returning a repeating field is, for example,

GetNthRecord(MyRepeatingField[2]; 2]

This seems to imply that I need a function that returns the nth repetition field (not its value since GetNthRecord needs a field). But such a function does not seem to exist. I tried

GetNthRecord(fieldname[Get(CalculationRepetitionNumber)]; n_record)

but that syntax is not allowed.

I have a feeling I'm missing something obvious. Any pointers?

Thanks...Andrew

Edited by Guest
Link to comment
Share on other sites

Hi AJV

OBVIOUSLY I haven't 8 Advanced today too...

but this calc for two records goes:

Let([

n_records = Get ( FoundCount )

];

Case (

n_records ; GetNthRecord ( GetRepetition ( number ; Get ( CalculationRepetitionNumber ) ); n_records ) * GetNthRecord (GetRepetition ( number ; Get ( CalculationRepetitionNumber ) ); n_records - 1);

GetNthRecord ( GetRepetition ( number ; Get ( CalculationRepetitionNumber ) ) ; n_records )

)

)

Link to comment
Share on other sites

Ray,

I tried

SimpleProduct (fieldname; n_records) =

If ( n_records > 1; GetNthRecord ( GetRepetition( fieldname; Get ( CalculationRepetitionNumber ) ); n_records) * SimpleProduct(fieldname; n_records - 1);

GetNthRecord ( GetRepetition( fieldname; Get ( CalculationRepetitionNumber ) ); n_records )

)

Seems the syntax is acceptable but there are only "?" in all repeating fields except for the first.

Did I misunderstand your suggestion?

Cheers...Andrew

Link to comment
Share on other sites

Ray,

I'm going to have to work on this some more. It seems the problem is with argument I'm passing to get n_records (as defined in the table). I'm calling my custom function with

SimpleProduct(Data::Value; Count(Extend(Data::Id))

If I use a simple scalar for n_records, for example:

SimpleProduct(Data::Value; 3)

the code in my last post works fine. So, I need to spend some thinking about how to use Extend (either in the field definition or in the custom function). It may be a couple of days before I can back to this.

Stay tuned...ajv

Link to comment
Share on other sites

Ok, I think I finally have this figured out. The problem was trying to pass a non-repeating field (n_records) and getting it "extended" within the custom function. The complete solution is really quite straightforward...

First, the custom function to do the multiplication can be written as:

Product(fieldname; n_records) =

If ( n_records > 1; GetNthRecord ( fieldname;n_records) * SimpleProduct2(fieldname; n_records - 1);

GetNthRecord ( fieldname; n_records )

)

The calculation repeating field in the master table for doing the calculation is simply:

SimpleProduct2( Data::Value; CountofRecords) // with multiple repetitions

where CountofRecords is also a calculation repeating field defined as

Extend(CountofIds)

and where CountofIds is the simple calculation field

Count(Data::Id)

The indirection for the counting of records seems like a kludge to me, but I was unable to get Count(Extend(Data::Id) to work.

That's it: no need to use GetRepetition or Get(CalculationRepetitionNumber)

Cheers...ajv

Link to comment
Share on other sites

Click on the "Help" in the Menu Above, OR HERE and then [color:green] Frequently Asked Questions and then jump down the list to [color:red] Posting Messages and then click on [color:red] Can I attach files to my post?

HTH

Lee

Link to comment
Share on other sites

Hi, AJV

many thanks !

But...were is this ?

Product(fieldname; n_records) =

If ( n_records > 1; GetNthRecord ( fieldname;n_records) * SimpleProduct2(fieldname; n_records - 1);

GetNthRecord ( fieldname; n_records )

)

By open with FM8 trial I can't see it into the Define Calc list of functions.

By open with FM7 Dev it seems as you have named it:

GetRowData()

but it don't appears into the list of custom in 7, neither in 8 !

Link to comment
Share on other sites

This topic is 6812 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.