Expand access of Record IDs in builder

Right now the Record ID can only be accessed when one is sending an email related to the object one is directly working with. But it would be useful to be able to access the Record IDs of connected objects as well. The Record ID could be an accessible field for each object, or all Record IDs could just be available from the email editor.


(If someone has a better way of putting this, let me know!)

Nice code David and Daniel! I agree with David that the view-based version is the best choice from client-side code for security reasons. Be careful out there :)

I posted the full code and instructions for saving the Record ID as a Field Value upon form submission, or record creation, using a view-based API request here:

1 Like

Sorry, I just realized I made an error in my prior comment. The header should be named Authorization, not Authorize.

17929538848 and everyone else on this thread: the code suggested by Daniel is insecure and should not be used. Instead, set 'X-Knack-REST-API-Key' to 'knack' and add this key below it: Authorization: Knack.getUserToken(). Your app's API keys should never be used in user-facing code, as they provide anyone with access to everything you can do in the builder.

Mark, could you provide more details on how it's stopped working? Is it showing any errors? If you'd like me to take a look at your app, feel free to message me at david@hmnd.io.

 

I could really use this as a feature. I have been using the code above as a work around for a year and it has recently stopped working. 

Please make the Record ID available as a field value in the builder. It would be very helpful to have when sending multiple emails in a form to include direct links to connected record IDs for the different users. Thank you.

1 Like

Thanks Dan! Very good tip! Going to try to implement now. 

Hi,

You can also add a Short Text and call it UID or similar, set as Required & Unique.

Then add the below code in the Javascript area changing the details to suit your database and ensure you have an edit form:

 


// Listen for a record being created
$(document).on('knack-record-create.view_221', function(event, view, record) {
// Set up PUT request to update the record
// Note that we use the URL for a separate edit form which has an input for the ID field
var url = 'https://api.knack.com/v1/pages/scene_156/views/view_225/records/' + record.id;
var headers = {
'X-Knack-Application-ID': '#####',
'X-Knack-REST-API-Key': '#####',
'content-type': 'application/json'
};
// Set our short text field's value to the newly created record's Knack ID
var data = { field_323: record.id }

Knack.showSpinner();
// Make the AJAX call
$.ajax({
url: url,
type: 'PUT',
headers: headers,
data: JSON.stringify(data),
}).done(function(responseData) {
console.log('Record updated!');
Knack.hideSpinner();
});
});

 

Then when you create a new record it will put the Knack UID in that Objects Field so you can see/use it (When done from the UI).

But I agree having it as standard make sense.

 

Thanks

Dan

Yes please! In order to simulate this behavior you can add an auto-increment field to the record and use that as a unique identifier, however since this field will (probably?) not be indexed in the DB this is always quite slow.

It would be super to have an easy way to access record IDs. Then, using a text formula, one could easily create static URLs for records, for users, for transactions, etc. For example, if you could just insert the record ID at the end of a search page URL sequence... #search/view-details/{record-ID}

Then... baboom! You have a [rofile URL for users, for important records in the database, that you can further embed into HTML code to make Like buttons for those URLs, buttons and more!

We really want to be able to create social media buttons for our objects, and just can't do this now, because we don't have a way to generate static URLs.

You guys already give access to the Record ID in the Email forms. It seems it would be easy to create a custom string like record-ID() that can work for text formulas.

1 Like

Hi,

Try this: https://support.knack.com/hc/en-us/community/posts/115000630992-Make-Record-IDs-Generally-Available-Potentially-as-an-Accessible-Field-in-all-Objects-?page=1#community_comment_115000662552

Thanks

Dan

Hi Dan,

Thanks for this. I took a close look, but it seems that your script only records the record IDs into the database as the records are made. Is my understanding correct? That's great, but, we've got all our old records that we need to reference somehow still. Any way to tweak your script to go over and capture all the previously generated records?

Thanks!

Please make Record ID available as field value in the builder. Would be very helpful to have when sending multiple emails in a form to include direct links to connected Record IDs for different users. Thank you.

Hi everyone - I know this is an old topic, but we’re exploring this feature request a little more and we could use some help narrowing in on the problem and start exploring some solutions.

In addition to everything that has been shared thus far, I’d love to hear from anyone who sees this and is still in need of better access to a record ID. Please let us know:

  1. What’s the main problem you face from not being able to access record IDs
  2. If you were to have that record ID available - from where and how would you ideally use it to solve that problem?

Thank you for your help as we work through this!

1 Like

I think the previous messages give a good overview of the needs but I would add one:

Speed-up troubleshooting when working with the API/custom code. Having an easy way to search by record ID would be good. Also being able to grab that id without using the dev tool would save time.

I think the record ID field should be there by default, to be honest. I know it could confuse new users though. Maybe it would be nice to have a developer view for more advanced users that would display all the advanced stuffs (field ids, record ids, etc …)

1 Like

Thanks, Loic! Integrations and customizations are certainly a valid use case. Our support team would also benefit from these types of features for similar reasons.

Side note: stay tuned for an update coming soon that surfaces field keys (field ids) in the builder!

It would be very useful to those who are working with the Knack API they could see in the records page on objects the Record ID just like the field keys.

Any update on this? I find that this is the missing crux of a lot of my own knack logic limitations… In most relational databases that I have used, there is always a ‘key’ field that identifies the record number… As of right now, there is no way to automate (without code) very basic API put commands…

5 years later. Still waiting on this feature…

3 Likes

Kudos, this feature would be greatly appreciated.