DEV Community

Oliver Flint
Oliver Flint

Posted on • Originally published at oliverflint.co.uk on

PCF primary entity info

Getting the primary entity info

At present the PCF Template provided by the Power Apps Cli gives us lots of opportunity and scope to improve functionality, but the type definitions are missing some objects that are present api. Now this could be for many reasons, one being support. Anyway, I'm a rogue so here is one I've already used a lot!

The entity id (guid)

const entityId = (context.mode as any).contextInfo.entityId;
Enter fullscreen mode Exit fullscreen mode

This is the equivalent of the following in the Client API

const entityId = formContext.data.entity.getId();
Enter fullscreen mode Exit fullscreen mode

The entity type (entity logical name)

const entityTypeName = (context.mode as any).contextInfo.entityTypeName;
Enter fullscreen mode Exit fullscreen mode

This is the equivalent of the following in the Client API

const entityTypeName = formContext.data.entity.getEntityName();
Enter fullscreen mode Exit fullscreen mode

The record name (primary attribute value)

const entityTypeName = (context.mode as any).contextInfo.entityRecordName;
Enter fullscreen mode Exit fullscreen mode

This is the equivalent of the following in the Client API

const entityTypeName = formContext.data.entity.getPrimaryAttributeValue();
Enter fullscreen mode Exit fullscreen mode

Hopefully this will be helpful to some of you!

Thanks for reading
Ollie

Disclaimer!
Some of the tips 'n' tricks in the PCF Tips 'n' Tricks category are to be used with caution. Although they may work at the time of writing, they may or may not be officially supported by Microsoft

Latest comments (0)