[βœ… Solution] How to get a Field ID inside workflow automations?

Is there a way to output the field ID of a field via a script? In this case I only get the file ID, but need the field ID

1 Like

@Roman

You can do something like this:

const response = await tape.Record.get(current_record_id);
const field = jsonata(`fields[label="Base"].field_id`).evaluate(response.data);
console.log(field);

just replace the β€˜label’ with the label of the field you are after, I am not sure if that helps or not thinking about it as maybe you don’t have the label?

Jason

2 Likes

Will just enhance @Jason’s great suggestion to use the script block with a little bit of API magic :magic_wand:

When retrieving records via the API, you will only receive the populated fields, but not the empty ones. That is why retrieving a field ID via such a call is not ideal.

Indeed, a second call to the App API will yield the full app config including all fields (link to docs).

Your code could look similar to this:

// load record ...
const record_response = await tape.Record.get(current_record_id);
// ... use app_id of record to fetch the full app:
const app_response = await tape.App.get(record_response.data.app_id);
// access your field as suggested by Jason
const field = jsonata(`fields[label="Base"].field_id`).evaluate(app_response.data);
console.log(field);
// proceed as required...

This will return all fields of the app, and should allow you to extract field IDs in any scenario.

Let me know how it goes! :star_struck:

Cheers
Tim

PS: I wiped a couple of responses from this thread, that were indeed unrelated (only caused by a typo / copy paste mistake) to avoid confusion. Above solution should resolve @Roman’s issue entirely.

2 Likes

This has worked wonderfully. :pray:
However, as i sometimes use an emoji in the field label, I used the external_id to identify the field.
I hope this ID will not change when cloning a workspace.

2 Likes