Was a record created through a form, grid edit, or API_AddRecord?

  • 0
  • 1
  • Question
  • Updated 5 months ago
  • Answered
  • (Edited)
I'd like to have a field that shows the following three text options: Form, Grid, API

Is there code that can detect how the record was created and paste one of these three results into my desired field? I'm trying to track users in our apps and this would help immensely with oversight for certain company initiatives.

Thanks for any help!!
Photo of Tyler Parker

Tyler Parker

  • 850 Points 500 badge 2x thumb

Posted 5 months ago

  • 0
  • 1
Photo of John Rogers

John Rogers

  • 420 Points 250 badge 2x thumb
Create a table called source. In that table make the records have a numeric value tied to each source. 1 = API 2 = form and 3 = grid. Place the related lookup field inside of your record form where you are wanting to track how these came in. Now when they do the api edit record call add their field ID to the call and the number is value 1 to be sent over. Same with the form. And with grid edit just make an action or automation that basically states if it comes in without a source then write grid edit in source, since you only have 3 options and the other 2 are taken care of.

There is probably a simpler way, but this way would be 100% automated.
Photo of Jonathan Heuer

Jonathan Heuer

  • 306 Points 250 badge 2x thumb
Interesting, but why would you need a new table? What about a multiple choice field with the three options:
  • Grid Edit (this is default value)
  • API (set this as part of any API call)
  • Form (use a form rule to change to this under appropriate circumstances)
Photo of John Rogers

John Rogers

  • 420 Points 250 badge 2x thumb
You technically wouldn't, I just did that because it is more organized incase future development your source becomes 30 instead of 3. Always build now, that which will work later without having to re-do :D! 
Photo of Jonathan Heuer

Jonathan Heuer

  • 306 Points 250 badge 2x thumb
Good point John
Photo of Tyler Parker

Tyler Parker

  • 850 Points 500 badge 2x thumb
Thanks a lot John, I'll try this
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 29,874 Points 20k badge 2x thumb
You could do this with a Service Worker but I think there would be more than three cases to decode. Basically the Service Worker would monitor network traffic and if it sees for example an ?a=er it would modify the network request to include an extra field indicating a form was used. Likewise, if ?act=API_* was seen it would modify the network request to include the extra field indicating an API was used. Similar arrangement for Grid Edit.

You would need to cover both GET and POST requests slightly differently and to be comprehensive you might want to record with imports separately.

The main challenge would be to discover and cover all the edge cases.
Photo of Tyler Parker

Tyler Parker

  • 850 Points 500 badge 2x thumb
Thank you too Dan, would you mind linking me the best sources to find more information on Service Workers and how to get started using them? I've read about capabilities you've mentioned in other posts and I have a programmer that is interested in testing them out in our apps.

(Edited)