Retrieve current record id

Hi, I’m creating validation on a custom form field as I’ve always done, so I take the competence file inside custom/Extension/modules… And I write my own javascript.
The problem this time is that I need some information that is not in the current module, but in the related module. So I would need to get at least the ID of the current record and then get the ID of the related module and get the record of this module.
I tried it this way:


but it results in NULL.
Do you have any ideas on how to do this? Thank you.

What kind of hook are you using to inject the JS?

While you’re still in PHP (server-side) you probably have all the ids you need; you can put them in your JS before injecting (make your JS a bit dynamic to write the correct id to a JS variable that you can then easily use).

I do not use a logic_hook, I created an entrypoint and took the file


and entered the code for validation:

$dictionary["<MODULE>"]["fields"]["<field_name"]["validation"] = array (
	'type' => 'callback',
      'callback' => "function(formname,nameIndex) {...}"	  

Ah, you can’t make it dynamic from there, I guess.

But try adding a JS breakpoint somewhere in your code (or other code on the page) and use the browser’s developer tools to inspect existing variables. I am sure it is referenceable somewhere. Maybe an existing variable, maybe an HTTP POST variable…

I agree with pgr.

In EditView inspecting the source code on a browser you’ll find something like:
<input type="hidden" name="record" value="55257327-e7e5-834c-1f24-627a6f2e7cdc">

The problem is that I don’t need it in Editview, but in the validation section (see above). The only thing I have managed to do is to take the link from the page title where the record id is passed in:

url=document.querySelector('.module-title-text a');
url2=new URL(url);
record = url2.searchParams.get('record');

, but I was hoping for something “less forced”

What kind of validation are you trying to achieve?

a check on dates and other module fields

Is this

useful for you?

I have no problem doing the validation, the only problem is finding the data to do the validation on.
Since the validation has to be done on the current module, I need to check fields that are only present in another module which is related to the current one. Hence my request, how do I get to fields in another related module? And I was wondering if I could at least reach the ID of the current module and then create a QUERY directly on the correlation table.

I do not see it in your question so wanted to ask:

Have you tried using the get_linked_beans method as explained in