Blog, Development

PCF: Lookup Attribute – Let’s take look under the hood

Lookup attribute was unavailable for PCF for a long time but the moment when it’ll become available and fully supported for developers of PCF controls is coming. In this post, I will take a look under the hood. All operations I will perform are technically unsupported so don’t use approaches I will use in your production environments.

Making Lookup Attributes available

In order to add lookup attributes to your control, it’s required to add the description of the attribute to ControlManifest.Input.xml file. Here is the list of different available Lookup attributes:

  • Lookup.Simple
  • Lookup.Customer
  • Lookup.Owner
  • Lookup.PartyList
  • Lookup.Regarding

In order to use one of the lookup attribute types in the PCF Control, the following description of the input can be used:

The issue here is when “npm run build” code is run – the following error is thrown:

In order to work around this error, the following steps can be performed:

  • Open \node_modules\pcf-scripts\featureflags.json file
  • change “pcfAllowLookup” setting from “off” to “on”:

Once the change is applied and the file is saved, control can be built without errors.

What’s new is the context

The most interesting pieces could be interesting for the developer are located in 2 different parts of the context so let’s check the first one – it is located in the “parameters” property of the context and to be more specific – under correspond lookup property. Here is what could be retrieved from that property:

  • context.parameters.lookupProperty.raw returns pretty much the same value as lookup attribute returns in usual JavaScript (and the value of the same format should be passed to the corresponding property in getOutputs method). Example:

  • context.parameters.lookupProperty.attributes.Targets gives an array of schema names of entities for a particular lookup control, there will be 1 value for “Simple” lookups and multiple for all other types of lookup attributes. Example for “Customer”-type lookup:

I was curious where I can find the extended configuration of the lookup like the set of views available for this lookup control, default view, and prefiltering if it is enabled. After some time I found an answer – all of the properties are located under context.utils._customControlProperties.descriptor.Parameters:

So as for example, if you want to get the default view id for the current Lookup Control – it’s possible to use the following code – context.utils._customControlProperties.descriptor.Parameters.DefaultViewId and so on regarding other properties like AvailableViewIds, FilterRelationshipName, and DependentAttributeName.

Don’t forget that this code is not supported yet and there is no guarantee that it will be one day, but, anyway, I hope it’ll become available and supported one day.

 

 

2 Comments

Leave a Reply to Betim Beja Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.