Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

Insert next record's field


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

Recommended Posts

Lookup rather than inserted....

Record_Id (autoserial num)

c_Next Record_Id = Record_Id +1

Selfjoin with c_Next Record_Id at left side and Record_Id at right side.

Your value

Your next value (lookup usingthe Selfjoin)

Could it suit your needs.

Link to comment
Share on other sites

It seems to me that whether a lookup or other technique is used it's going to need a script to trigger it. Might as well use a simple loop in that case:

Sort [restore, no dialog]

Go to Record/request [first]

Loop

Set Field [gValue, Value]

Go to Record/request [next, exit after last]

Set Field [Value, gValue]

End Loop

Link to comment
Share on other sites

Hi,

The way I lock the lookup is changing the calc from

c_Next Record_Id = Record_Id +1

to

c_Next Record_Id = Case(flagkey = 0, Record_Id +1, (Record_Id +1)&" 0")).

The flagkey is a num field entered once by script when I first "leave" the record.

But Vaughan is right. Yep.

In fact, the way I use it is slightly different. As Lee pointed it, I use it for creating records, and this makes a big difference (I think)

Link to comment
Share on other sites

Hi,

The 'RecordID + 1' approach may appear to work over small numbers of records, but it will break if you use it more widely, because Status(CurrentRecordID) numbering is only contiguous within defined ranges (as explained in FMI kbase article #104663 at http://www.filemaker.com/ti/104663.html ).

The method you've described will also break even when it falls within one of the ranges of contiguous IDs (as outlined by FMI) whenever/wherever a record has been deleted.

Next record lookups can be made to work reliably (in all cases where there *is* a next record), by referencing the current recordID within the index of the recordID field (retrieved using the ValueListItems( ) function) and then parsing the index to retrieve the next sequential value.

The calc which performs the parsing must then be linked to a data field so that it will be triggered by a user action, and defined as the key field in a relationship to the recordID field. Lookups which are based on the relationship will then copy values from the next record when the user performs one of the actions that has been defined as a trigger for the calc.

No scripts required... smile.gif

Link to comment
Share on other sites

Hi Ray,

Thanks for pointing this out to me !!!!

May this make a difference if I tell that the Record_Id is in fact a serial number, that I use with a lookup for a max 50 records per category.

I use this method to identify that line 0005g4g5dsqq556 of my line item is in fact the second line linked to the Invoice 125.

That means that the final calc with the record_id lookup stuff will be INV125-1, INV125-2, INV125-3,.... and that a new INV126 will automatically set the calc to INV126-1 as the lookup is set to enter 1 if no match value has been found...

If not (and anyway cause I'm sure your method is more reliable), could you be more specific for the second part of your post.

Are you saying that the left and right part should be :

c_key = ValuelistItems(Status(CurrentFile...), "Record_IDVList")

and the field to retrieve should be another calc

c_fieldForLookup = LAST(ValuelistItems(Status(CurrentFile...))+ 1

or

Max(Selfjoin::ValuelistItems(Status(CurrentFile...))+ 1

or

Middle(Position,...."PP",...) to extract the last occurence )+1)

Thanks for clearing me/us on this very good point.

Link to comment
Share on other sites

Hello Ugo,

Using a serial number field rather than a recordID will address the first part of the problem but not the second - the 'solution' will still break if a record is deleted (or if for any other reaons, your serial numbers happen to be non-contiguous).

The alternative method I suggested can be used in an *unstored* calc which will reliably reference the next record (if there is one), and can be used to trigger a lookup, or simply to display fields from the adjacent record on the current record. The calc would be along the lines of this:

Middle(

ValueListItems(Status(CurrentFileName), "IDs") & "

Link to comment
Share on other sites

See attached demo for a working model.

The NumToText is not essential, providing your recordID and key field calc result types match.

The method is not suitable for use with totally random IDs, since it depends on the index order (sorted as per the characteristics for the field type of the recordID field) to match the creation order of the records.

AdjacentRecord.zip

Link to comment
Share on other sites

Ok Ray, I got it. Thanks a million.

I had exactly the same....but....as I use a FRench version, I didn't copy/paste your calcs.

Sometimes, it allows me to understand what I'm doing, but in that case I added a " ) " at the end of " Sign(Length(NumToText(recordID))) " from the second line of your 1st calc.

Strange FM didn't warned me. I suppose the calc was just good but for other purpose.

Thanks again. As you said. Very robust.

Link to comment
Share on other sites

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