Moving to a particular record

This might help. Every table you create has a primary key. Start a new table called “Company” and Servoy will propose a first field called “companyid”. You can change it to whatever you like but once it’s finalized it cannot be changed. That’s your primary key or “pk”. Add a new record and the value in the PK field is advanced by one, automatically.

That’s what that little routine is doing, capturing the current record’s PK value and saving it into a variable. After you re-establish the foundset you’re simply returning to that record. Give it a try.

The most difficult part of learning a radically new skill is right at the beginning when you’re swamped with foreign terms and most of the explanations refer to six other complex things you’ve never heard of before. The second most difficult part is communicating with more experienced hands who talk way over your head, unconsciously assuming a foundation that just isn’t there. Requires patience, not only with others but also with oneself.

I spent days trying to figure out whether a variable has a life beyond the current method. Globals in FMP certainly do and variables is just another form of a global, right? Or so I thought in those first days. Next I faced the bewilderment of how to move a variable value from one method into another. Spent close to a week on this one. The docs explained it all in highly technical terms I can now understand, but at the time was as clear as mud. I went through two or three contributors to this forum who provided me with utterly incomprehensible answers because they were assuming I already had a grasp of foundations I never knew existed. Finally someone saw my blind spot.

It takes time. I’m currently about eight weeks behind where I assumed I’d be when I started last June.

Just this past week I finally made breakthrough on addFoundsetFilterParam, an ongoing problem for at least a couple of months. The existing documentation on this particular function sucks (sorry Marc and Maarten, but it clearly does). A critical key factor just wasn’t there, a piece of knowledge all my correspondents on this Forum just assumed I understood. They glided over the critical factor assuming I already knew it. (No, I’m not trashing anybody. Docs can and do have omissions and misdirections just like code does. The most important thing is to fix it.)

This is a young program, just as we all are as programmers within it. This programming environment is awesome.

Morley:

You’re way ahead of me (and more articulate :D) and for that I’m very appreciate. I get to learn from your inquiries.

On that note, following how I think I interpreted your and Edward’s example,
I would think that replacing serialid with the actual field that is the pk field would do the trick.

It’s not.

What am I not understanding about this functionality?

Thanks for all your help in advance!

Providence1:
Morley:

You’re way ahead of me (and more articulate :D) and for that I’m very appreciate. I get to learn from your inquiries.

On that note, following how I think I interpreted your and Edward’s example,
I would think that replacing serialid with the actual field that is the pk field would do the trick.

It’s not.

What am I not understanding about this functionality?

Thanks for all your help in advance!

You’re probably overdoing it, something I’m frequently guilty of as well. It’s actually simpler than you think. Recommend you create a new method just to test and debug this routine. Keep it dead simple until you get your bearings.

// Do a find so you're displaying just a subset of all your records
// Set your global field so step 2 below will work
var dupFoundset = controller.duplicateFoundSet(); // store the foundset in a variable 
controller.loadRecords(globalToCustomerNameRelation); // jump to the desired record 
var i = serialid; // store the record's serial 
// This is the critical problem you're having. Look at the field definitions for the table 
// of your current form. Discover which is the primary key. 
// It's the field with "pk" in Row Ident column. Note down the field's name.
// Substitute that field name for "serialid" above.
// The record number stored in the pk field will be stored in the variable.
// The following line will show you what's been stored in that variable.
application.output('i = ' + i);
controller.loadRecords(dupFoundset); // restore the foundset 
foundset.selectRecord(i); // jump to the desired record

That’s it. You’re storing the primary key value in the variable “i”. After restoring your foundset (second last step) you’re jumping to the record with the pk of what you stored in “i”.

Give it a run. When it finally works, slap your forehead in amazement at how difficult you made it for yourself. :P

It’s grabbing the pk for the first instance of the CustomerName from the ENTIRE table, not the first pk instance of the CustomerName of the foundset.

[no matter what I do to the global_to_CustomerName_relation or the serialid(pk)]

Any ideas?

BTW, the method is running from the form in the tabpanel that is shown in a related parent form.

Here’s actual code from a test method within my solution:

globals.gint1 = company_id;
var dupFoundset = controller.duplicateFoundSet(); // store the foundset in a variable
controller.loadRecords(gint1$to_com); // jump to the desired record
var i = company_id; // store the record's serial
controller.loadRecords(dupFoundset); // restore the foundset
foundset.selectRecord(i); // jump to the desired record

It works.

However it definitely WON’T work if the record you want to jump to is not within the foundset. There might be a way to add your target record to the found set, but I’m not yet skilled enough to know how to do that.

Kind regards,

With Mr. Cusick’s help, this did it:

var runtot = 0
var rec = 0

for ( var i = 1 ; i <= controller.getMaxRecordIndex() ; i++ )
{
runtot = runtot + nordqty
inqueue = runtot
if(ccustno == globals.gCustomerNo)
{
rec = i
globals.gInQueueNum = inqueue
}

foundset.setSelectedIndex(foundset.getSelectedIndex()+1)
}

controller.setSelectedIndex(rec)

Hope this helps others!