Put a record-id to local storage for use in a form

This is quite technical, but it could be of use for some.

Description of the case
In an hour registration tracker, I pre-make daily-records with make.com for all employees. That prevents them from doing it themselves and provides an opportunity for the admin to see when someone forgot to fill the daily sheet.
For the time entries, I want this to connect to the existing record in the daily entries table. So we can make summaries of all time entries on a particular day.

The challenge
How to get the daily entry connection automatically into the form, and without the possibility to use a details component, where you could write a field into memory.

How to do it

  1. Add a list of all daily entries and filter it to the logged-in-user and the current day. Result: 1 record in the list.
  2. In the builder, you add the record id to the list, and you give it a class.
  3. Use TB-render function and within jQuery to identify the value of the record id.
  4. Because the record-id gets too much data from the field, you need to sanitize the variable, so you are left with only the record id as a value
  5. The variable you will write in the local storage of the browser so you can use it in the form.
  6. Hide the component you have used to get the record_id, because you don’t need that anymore.
  7. Within the form with the record rules, which run after you press save, you write the record-id for the connection into the new record.

The Javascript

TB.render('component_xx', function(data) {
    // identify and get the value you want to write to memory
    var dailyEntryRecordId = $(".daily-entry-record-id").text().trim();

    // Sanitize the unneeded text in the variable
    var recordId = dailyEntryRecordId.replace("Record ID", "").trim();

    // add the value to local storage with the  identification 'daily_entry_record_id'
    localStorage.setItem("daily_entry_record_id", recordId);

    // console.log is not needed, but gives you a check possibility
    console.log("Daily Entry Record ID:", recordId);
    // hide the component after you have the value
    TB.hideComponent('component_xx');
});

Replace component_xx with your component.

Some screenshots

1 Like