Get index from selected record in lookup window

How to get the index from the selected record in the lookup window?

I have a form which shows a document and for the current selected document there are “follow-on documents” for which I use a lookup window, so that the user can see and maybe select one of these “follow-on documents”. If the user selects a “follow-on document” the form should show the selected document by the user instead of origin document, so I need to switch to this document.

Isn’t it easier to use this function?

foundset.selectRecord(pk);

Then you don’t need the index, just the pk.