Make Record IDs Generally Available/ Potentially as an Accessible Field in all Objects

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:

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.

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.