Can't retrieve connected record field

New to javascript and fumbling my way towards a method to use a record (draft invoice) to spawn multiple new records (final invoices - one for each client related to a case).

Right now I'm just trying to get the hang of working with records, and while I can retrieve a connected record's ID, I'm struggling with how to access the rest of the data.

Thanks for your help!

$(document).on('knack-record-update.view_292', function (event, view, record) {

var client = record.field_195_raw[0];
alert("clientID: " + client.id); //this alert displays the ID

var clientName = client.field_40;
alert("clientName: " + clientName); //this alert displays “undefined”

var clientNameRaw = client.field_40_raw;
alert("clientName: " + clientName); //this alert also displays “undefined”

});

Absolutely - thanks!

Hi Fred,

You're trying to retrieve connected field data that doesn't exist without accessing the data in a 'lookup'. If you log record.field_195_raw[0] to the console (and view it Google Chrome) the output looks like:

Object {id: "56a8616f1097b2613a7d95ed", identifier: "Johnny Customer"}

So the only data that comes with field_195 is the id of the client and the identifier that's displayed.

To set variables for both:

var clientID = record.field_195_raw[0].id;
var clientName = record.field_195_raw[0].identifier;

If you need any other data from the client object, you'll need to use an Ajax data access call using the id.

Hope that helps.