Forum Discussion

TylerParker's avatar
TylerParker
Qrew Assistant Captain
6 years ago

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

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!!
  • 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.
    • JonathanHeuer's avatar
      JonathanHeuer
      Qrew Cadet
      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)
    • JohnRogers3's avatar
      JohnRogers3
      Qrew Trainee
      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! 
  • 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.
  • TylerParker's avatar
    TylerParker
    Qrew Assistant Captain
    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.