Get the Form Number and Record ID, Javascript

talkinggoat

Member
I have created a button that will pass the ID# through the URL, then autofill a field in the form, but I need to get some information from Fabrik. From the details page of a record, I can see the form number and record ID in the URL as index.php/49/2 where 49 is the form, 2 is the record's unique ID and I'm in the record's details page, but how do I access that data, in Fabrik, if the ID is constantly changing?

I know I can see and retrieve the information in the JS console, using
JavaScript:
Fabrik.getBlock('details_49_2').elements.get('job_types___id').get('value');

As you can see, I can hard-code the record's information, but the button requires that the ID change from record to record. I can store that as a variable and use it just fine, but what happens when the ID of the record changes and I start looking at another record; details_49_3, for instance? The button will stop working.
 
Last edited:
I don't know if this solution will hold up, but it's predicated on the possibility that the first sub object of "blocks" will always be in the [0] or the first position.

JavaScript:
Object.values(Fabrik.blocks)[0].elements.get('job_types___id').get('value');

Screenshot-from-2019-05-08-12-39-33.png

This will return the ID number for this particular Fabrik element and this particular entry in the database. I can pull the name of this entry by using :

JavaScript:
Object.values(Fabrik.blocks)[0].block
will return details_49_2
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top