Getting JavaScript to run properly with IOL

  • 1
  • 2
  • Question
  • Updated 5 months ago
  • In Progress
Hi everyone,

I have two tables, one that has a full list of records, and another table, [Modified Records], where a record is added to [Modified Records], which is triggered every time a record in the full list is edited. I have the IOL set up properly for [Modified Records] and want the script to run every time a record is automatically added. Although records are being automatically added to [Modified Records], it is not triggering the script to run. I have the field, variables for the app, and the form set up properly. 

I personally think that, although a record is being added to [Modified Records] automatically, we are not manually creating a new record and that's why the script isn't being executed.

How do I get this code to run?

Thanks
Photo of John Barulich

John Barulich

  • 634 Points 500 badge 2x thumb

Posted 5 months ago

  • 1
  • 2
Photo of John Barulich

John Barulich

  • 634 Points 500 badge 2x thumb
Bumping my post and adding context:

The whole reason we created this [Modified Records] table was to handle the different cases where the user would edit/create a record. Sometimes a user would click 'New Record' to add another record, and sometimes the users use grid edit to add another record. This [Modified Records] table holds the records that have been edited or created, whether through the 'New Record' or through grid edit.

This was an attempt to simplify all creations and edits into one table, where I would access this [Modified Records] table and make proper changes to certain fields in the full records table, instead of writing separate scripts for when the grid is edited and when a 'New Record' is created.

Would a service worker be better suited for this problem? I originally thought my idea was a solid solution but since the code doesn't run using the IOL, I'm not exactly sure how to proceed.

Still need any help,

Thanks
(Edited)
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,572 Points 20k badge 2x thumb
I am having a hard time understanding what you are trying to accomplish. It would help if you described what you want to achieve in simple language without any reference to IOL, SW or MO. There may be a native solution available.

One key distinction is that native features like webhooks, actions, automations cannot run user supplied script - they do their thing on the back-end according to how they are configured. If they can't be configured through the UI to accomplish your goal you have to use script. If you need script to run this has to be done in the browser on the front-end.
(Edited)
Photo of John Barulich

John Barulich

  • 634 Points 500 badge 2x thumb
Hey Dan,

Thanks for your time as always.

This project has two tables. One table has a list of all records that have a van ID, start mileage, and ending mileage.

I currently have a script that automatically sets the start mileage to the ending mileage of the same van from when it was previously used, every time a record is created.

However, there will be a time where several vans are scheduled in advance, where the ending mileage may not be known, and that starting mileage may not exist because it's previous ending mileage is not known.

Because the workers sometimes update the record through grid edit, we had no way of knowing what was edited and the script can't run. So we created a table, [Modified Records], that has a trigger which adds records to it when a record is edited.

The problem is the script doesn't run when an edited record is automatically added to [Modified Records], which is why I don't know how to proceed.

Thanks for your time
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,572 Points 20k badge 2x thumb
I would imagine there are four fields associated with your primary table:
[start mileage]
[ending mileage]
[start date]
[end date]

Assuming [start date] and [end date] were always entered and there were no overlaps between records the script could sort the records in ascending order and fill in the missing mileages. If the [start mileage] was missing it could be filled in based on the prior record's [end mileage]. Likewise if the [end mileage] was missing it could be filled in based on the next record's [start mileage]. There would be some cases where you could not fill in missing mileages if there was a span of records where neither start or end mileages were recorded,

To implement this I would place a button atop the relevant report and when the button was clicked it would calculate the missing mileages, throw up a dialog box to confirm the changes, make the changes and reload the page, The interface might look like this in terms of a button atop the report but without the checkboxes (process all records in the report):

Process Selected Records
https://haversineconsulting.quickbase.com/db/bkfwuwx2p?a=td
(Edited)
Photo of John Barulich

John Barulich

  • 634 Points 500 badge 2x thumb
Thanks Dan,

But couldn't this be a good job for a Service Worker? I would like to know how to detect changes in the DOM from grid edit and make changes when listening for mutations. Is this an option?