Getting all field values for an entity

Here’s a little scripting snippet for how to retrieve all the information about an entity, without knowing or hard-coding the space name, database name or field names:

const fibery = context.getService('fibery');
// get entire schema
const schema = await fibery.getSchema();
// get specific database (type) name
const typeName = args.currentEntities[0].type;
// filter the schema for the specific type and get all field names
const fields = schema['typeObjects'].filter((obj) => obj.name == typeName)[0]['fieldObjects'].map((field) => field.name);
// get all entities with all fields
const entitiesWithAllFields = await fibery.getEntitiesByIds(typeName, args.currentEntities.map((entity) => entity.id), fields);
// send result to the browser console
console.log(entitiesWithAllFields);
6 Likes

Your exact script has as output for me, when applied to the current entity of database ‘CCE Root/Page’:

Failed to execute Action “Script”: getEntitiesByIds: There is no relation for ‘CCE Root/Page’ database whiteboards/whiteboards field.

Yeah, it seems that it won’t work if the Whiteboards or Documents field is enabled (whiteboards and documents are technically views, so you can’t query them like you can for fields and relations).

To avoid the issue, I suggest using replacing this

const entitiesWithAllFields = await fibery.getEntitiesByIds(typeName, args.currentEntities.map((entity) => entity.id), fields);

with this

const entitiesWithAllFields = await fibery.getEntitiesByIds(typeName, args.currentEntities.map((entity) => entity.id), fields.filter((f)=> f !== 'whiteboards/whiteboards' && f !== 'documents/documents'));

3 Likes