Power Pages Portals

Learn how to install KeyNamics within your Power Pages Portal.

After KeyNamics has been fully configured & installed navigate to your Power Pages portals URL.

The URL for your portal will typically be in the form https://{yourportalname}.powerappsportals.com where {yourportalname} represents the name choose for your portal during portal set-up. If your portal administrator has configured a custom domain name for your portal you may need to contact your portal administrator to confirm the URL you should to access your portal.

If you are the portal administrator you can visit https://make.powerapps.com/ and click "Apps" on the left. You should see your portal application listed and you can browse to the portal as shown below...

image

Once you've navigated to your Power Apps portal KeyNamics will be available on one or more pages within your portal.

KeyNamics is generally installed and configured by Omfax Systems within your Dynamics environment and portal administrators would generally not need to worry about configuring portal pages. For completeness details on how KeyNamics can be added to portal pages is provided below.

Installing KeyNamics for Power Pages Portals

To support different scenarios KeyNamics for Power Apps portals can be embedded on a Power App Portal page in a few different ways. We refer to these scenarios as...

  • Minimal Keyfax is launched via a simple hyperlink from the portal page. Results are handled via a Power Automate Flow.

  • Entity Form Keyfax is launched via a Basic or Advanced entity form embedded on the portal page. Results are handled either via field mappings to update the entity form or via a Power Automate Flow.

Both scenarios are demonstrated further below. With either scenario portal page layout and styling can be customized to perfectly reflect your organizations branding. All styles used by KeyNamics within portal pages use the standard Bootstrap styles provided by Power Apps portals.

Minimal

At a minimum you can embed KeyNamics on a Power App Portal page using a regular anchor tag (hyperlink). You can see in the screen grab below we have a single button that launches Keyfax...

image

For reference the HTML & liquid code for this portal page are provided below...

When the "Launch Keyfax Scripts" button is clicked the launchUrl() method is called within the keyfax.js JavaScript file to create the users KeyNamics session and open Keyfax within a pop-up window. This is shown below...

image

The tenant would typically walk through the script until completion. Once complete the opening portal page is made aware Keyfax has completed, this is shown below...

image

Developers can leverage several client side events exposed by the KeyNamics for Power Apps portals JavaScript API to implement custom functionality once Keyfax completes or is cancelled. For further information see the "Customizing the KeyNamics for Power App Portal JavaScript" section within this guide.

If the minimal scenarios is used it's recommended portal administrators leverage Power Automate Flows to perform any additional post-processing of Keyfax results. For further information on this please refer to the "Using Power Automate Flows to process Keyfax results" section of this guide.

Entity Form

To leverage the field mapping functionality offered by KeyNamics portal administrators can also embed KeyNamics within any portal entity form. Field mappings can be used to then send field values to Keyfax to provide context aware scripting or update fields on this form with information from Keyfax once Keyfax completes.

You can see an example of KeyNamics embedded within a basic portal entity form below...

image

As with the minimal scenario when the "Launch Keyfax Scripts" button is click Keyfax is presented within a pop-up window as shown below...

image

Once the portal page detects Keyfax has completed fields on the form are updated based on configured "Receive from Keyfax" field mappings within KeyNamics. You can see below we've updated two fields with results from Keyfax...

image

In addition to using field mappings to update entities within Dataverse with results from Keyfax portal administrators can also leverage Power Automate Flows to perform additional post-processing of Keyfax results. For further information on this please refer to the "Using Power Automate Flows to process Keyfax results" section of this guide.

For reference the HTML & liquid code for this portal entity form are provided below...

You will notice within the above code example the entity form is embedded within the portal page using the `

` liquid tag. The name supplied here matches the name of our Basic Form within the portal as shown below...

image

The "Portal Test Form" has a web resource field with the name WebResource_Keyfax. At run-time this web resource is replaced with the KeyNamics launch button and status label. You can see an example of this below...

image

When embedding KeyNamics within a entity form it's important to ensure the currentEntityName property is updated within the KeyNamics for Power Apps portals JavaScript to align with the entity being used by the entity form. For example if we are displaying an entity form to allow users to create jobs and the jobs form is associated with a new_jobs entity within Dataverse we should update the KeyNamics for Power Apps portals JavaScript code embedded on the portal page as shown below...

This allows you to configure entity specific field mappings within KeyNamics that will only be applied for the new_jobs entity or when the jobs form is presented. This is helpful if you wish to present KeyNamics within several different entity forms and apply different field mappings for each form.

Understanding Sessions and Results within KeyNamics

Sessions (keyfax_session)

When KeyNamics is launched an entry is always added to the keyfax_session entity within Dynamics to represent the users KeyNamics session. This provides the user launching KeyNamics with a global unique identifier to represent the session which is then used for subsequent requests to obtain session specific data. You can review all created KeyNamics sessions via the "Sessions" link available within the KeyNamics model driven app as shown below...

image

Results (keyfax_result)

When KeyNamics completes results for the Keyfax script are always added to the keyfax_result entity within Dynamics. You can review all created KeyNamics results via the "Results" link available within the KeyNamics model driven app as shown below...

image

For convenience the results produced by Keyfax are available within the keyfax_result entity as both XML and JSON. You can review each result entry within the Results area of the KeyNamics app to view this XML or JSON.

Sessions & Results are automatically purged

By default any entries older than 31 days within the keyfax_session and keyfax_result entities will be automatically deleted by two System Jobs defined within Dynamics. The purge duration for these entities can be adjusted via the BulkDeleteSessionPurgeDays & BulkDeleteResultPurgeDays KeyNamics settings.

For further information see the "New System Jobs" section within #864

Understanding the KeyNamics lifecycle

When KeyNamics is launched either manually via a hyperlink or automatically via an event the following steps are followed.

Launching Keyfax

  1. Create KeyNamics Session - The clients browser makes a POST request to /_api/keyfax_sessions. This adds an entry into the keyfax_session entity within Dataverse to represent the users KeyNamics session. This POST request returns a global unique identifier or GUID to represent the clients session. This GUID is later used within subsequent requests to identify the users KeyNamics session. From here on in we will refer to this GUID as the KeyNamics Session ID.

  2. Invoke LaunchKeyfaxUrl action - Upon receipt of a KeyNamics Session ID the clients browser then makes an additional POST request to /_api/keyfax_sessions/Microsoft.Dynamics.CRM.keyfax_LaunchKeyfaxUrl supplying the KeyNamics Session ID. This invokes the LaunchKeyfaxUrl action. The LaunchKeyfaxUrl action is C# server side code hosted within Dynamics and is responsible for taking the "Send to Keyfax" mappings defined within KeyNamics and constructing the start-up data required by Keyfax to return a launch URL. The LaunchKeyfaxUrl action posts this start-up data to Keyfax to obtain a unique launch URL and then updates the keyfax_session entry within Dynamics matching the users KeyNamics Session ID.

  3. Get KeyNamics Session - Once this LaunchKeyfaxUrl action completes and launch information has been successfully added to the keyfax_session entity within Dynamics the clients browser then makes an additional GET request to /_api/keyfax_sessions to obtain the Keyfax launch URL for the users KeyNamics session.

KeyNamics will now launch Keyfax within a pop-up window. The tenant would walk through the Keyfax script until completion.

This is further illustrated below...

KeyNamics for Power Apps portals - Launch Flow 2 drawio

Obtaining Keyfax Results

Upon completion of a script KeyNamics adds the Keyfax script results to the keyfax_result entity within Dataverse. The results are available in both XML and JSON form via the keyfax_xml and keyfax.json columns within the keyfax_result entity. The keyfax_result entity is populated as follows...

  1. Create KeyNamics Results - Upon completion of a script the clients browser makes POST request to /_api/keyfax_results to create an entry within the keyfax_result entity within Dataverse representing the results for the users KeyNamics session. This call returns back a global unique identifier the client can use to identify the results. We will refer to this global unique identifier as the KeyNamics Result ID.

  2. Invoke GetResult action - Upon receipt of the KeyNamics Result ID the clients browser makes an additional POST request to /_api/keyfax_sessions/Microsoft.Dynamics.CRM.keyfax_GetResult supplying the KeyNamics Result ID. This invokes the GetResult action. The GetResult action is C# server side code hosted within Dynamics and is responsible for obtaining results from Keyfax and exposing these results via "Receive from Keyfax" mappings to update entity forms or via the keyfax_result entity.

  3. Get KeyNamics Result - Once the GetResult action completes and results have been successfully added to the keyfax_result entity within Dynamics the clients browser then makes an additional GET request to /_api/keyfax_results to obtain the "Receive from Keyfax" mappings necessary to update fields if KeyNamics is embedded within a Basic or Advanced portal entity form. If KeyNamics is not embedded within an entity form within your portal you will likely need to use a Power Automate Flow to perform custom processing against the results added to the keyfax_result entity within Dataverse.

This is illustrated below...

KeyNamics for Power Apps portals - Results Flow drawio

To monitor health and performance whenever KeyNamics is launched or results are obtained we measure & log the following timing metrics...

  • Request Time The number of milliseconds it took the clients browser to perform a POST request into Dataverse

  • Keyfax Execution Time The number of milliseconds it took the server side Dynamics action to communicate with and parse the response from the Keyfax Web API

  • Action Execution Time The number of milliseconds it took in total for the server side Dynamics action to execute. This includes the Keyfax Execution Time.

To track the client request time an additional HTTP request is necessary. We feel this is a worthwhile tradeoff as the additional request should be negligible under normal circumstances and capturing this client request time can helps isolate KeyNamics performance problems.

The above metrics are available for review via the Sessions or Results links within the KeyNamics model driven app or via the complimentary Power BI dashboard provided with KeyNamics.

Using Power Automate Flows to process Keyfax results

With Power Automate Flows you can use a low-code, drag-and-drop approach to develop optional, automated flows to perform additional post-processing of data produced by KeyNamics.

To give you a sense for what's possible Power Automate Flows can be used to...

  • Manipulate any entity within Dataverse when Keyfax is launched

  • Manipulate any entity within Dataverse when Keyfax completes or is cancelled

  • Integrate with hundreds of 3rd party connectors to automate common tasks

  • Trigger additional notifications (post to Slack / Trello or send SMS / push notifications)

  • Make smarter decisions leveraging artificial intelligence with AI Builder

Creating a Power Automate Flow

Power Automate Flows typically represent business workflows and as such are often unique for each organization. For this reason we cannot provide a one size fits all flow however here we'll aim to offer some general examples and tips & tricks to help you quickly develop a unique Power Automate Flow to interact with KeyNamics.

To help you get started we'll create a simple Power Automate Flow to send a few example emails & update an example entity within Dataverse whenever results are added as a result of a user completing a script within KeyNamics.

  1. Visit https://flow.microsoft.com/

  2. Click Create within the menu on the left

  3. Selected Automated Cloud Flow as shown below...

image
  1. Provide a name for your flow. For the trigger choose "When a row is added, modified or deleted" for Microsoft Dataverse. This is shown below...

image
  1. Once you've created the flow you'll see the following screen...

image
  1. Update the trigger as shown below, this will ensure the flow will execute only when new Keyfax results are added to the keyfax_result entity within Dataverse. In this example whenever the keyfax_xml column within the keyfax_result entity is modified the flow will execute. The keyfax_xml column holds the final results for Keyfax scripts within XML format within Dataverse. The important trigger properties to update are...

  • Change type: Added or modified

  • Table name: Results

  • Scope: Organization

  • Select columns: keyfax_xml

TIP The keyfax_json column provides Keyfax results in JSON form. If you prefer to work with JSON you may wish to monitor for changes on the keyfax_json column and not the keyfax_xml column.

The above trigger is shown below...

image
  1. To make it easier to work with the result XML, we'll first add this to an XML variable within our flow. You'll need to add a variable action and define as shown below...

image

The expression for this variable is xml(triggerOutputs()['body/keyfax_xml']). Within the flow we can now refer to this variable and execute XPath expressions against this XML to iterate with the XML or pull out specific elements.

  1. To further demonstrate this let's create another variable called Actions. This variable will use an XPath expression to return a collection of all action XML elements within our Keyfax results. You can see this below...

image

The expression for this variable is xpath(Variables('Xml'), '/KeyfaxData/Call/Action')

  1. Next we'll create an "Apply to each" action within the flow to iterate each <Action/> XML element within the previously defined action variable. We'll check the type of action and if the action is of type "Email" we'll send an email from the flow. The basic action is shown below...

image

During each iteration we can execute XPath expressions against each found <Action/> XML element as shown below...

image

The full expression for the condition action is xpath(xml(item()), 'string(/Action/TaskTemplate/Task/@Type)'). We check the value of the type attribute and if this equals "Email"" we trigger an email action as shown below...

image

You can see we pull out the recipient, subject and body for the email from the KeyNamics results using the following expressions...

  • xpath(xml(item()), 'string(/Action/TaskTemplate/Task/Email/Addresses/To)')

  • xpath(xml(item()), 'string(/Action/TaskTemplate/Task/Email/Subject)')

  • xpath(xml(item()), 'string(/Action/TaskTemplate/Task/Email/Body)')

It's important to remember that Keyfax will send configured emails and task emails don't need to be sent via a Power Automate Flow. We've used this example to demonstrate more advanced ways developers can interact with the XML provided by KeyNamics.

  1. Finally you can see below whenever our flow is triggered we can update any other entity within Dataverse with information from the KeyNamics result. In the example below we are adding a new row to a Test entity within Dataverse and setting the Name column of this new row to the global unique identifier issued by Keyfax to uniquely identify the Keyfax session. This is shown below...

image

The full XPath expression to populate the name column with the Keyfax global unique identifier from the result XML is xpath(Variables('Xml'), 'string(/KeyfaxData/GUID)').

Further Flow Considerations

  • Keep it simple (At least at the beginning)

  • How is your flow handled when the user cancels the Keyfax script

  • How is your flow handled when the keyfax_session or keyfax_result entities are automatically purged

  • How is your flow handled for different script types (if your installation supports multiple Keyfax script types)

Example Results Produced by KeyNamics

The results shown below are for example purposes only and do not represent real world results. These results are just provided as a convenience to show the most common elements exposed by Keyfax Please review the final Export XML produced for your KeyNamics installation by visiting the Results page within the KeyNamics app and inspecting the XML column.

Repairs Online (minimal example JSON)

Repairs Online (minimal example XML)

Enquiries Online (minimal JSON example)

Enquiries Online (minimal XML example)

Customizing the KeyNamics for Power App Portal JavaScript

All client-side JavaScript required for KeyNamics for Power Apps portals is located within the keyfax.js JavaScript file. This file is added to your portal as a web file and referenced from the portal page that launches KeyNamics.

KeyNamics for Power Apps portals offers a single window.keynamics.init(options) method to both configure and initialize KeyNamics. The keynamics.init method would typically be called from the page load event within your portal page.

Important KeyNamics for Power Apps portals JavaScrip Properties

When initializing the KeyNamics for Power Apps portals JavaScript you can define a number of optional properties. These are described further below.

Available KeyNamics for Power Apps portals JavaScrip Events

When initializing the KeyNamics for Power Apps portals JavaScript you can define a number of optional events. These are described further below.

Understanding how KeyNamics is aware of the authenticated portal users

To ensure KeyNamics for Power Apps portals is aware of the authenticated portal user you must include the following liquid code within any portal page containing the keyfax.js JavaScript file. This liquid code populates a hidden field with the users contactid if they are authenticated within your portal...

With this liquid code present within the portal page you can leverage the "Portal - the authenticated portal users contactid" source type option available within KeyNamics field mappings to automatically obtain the authenticated portal users contactid from the contacts entity within Dynamics as shown below...

image

The mapping can then be used to perform subsiquent FetchXML queries to obtain additional contact details...

image

In this example we are obtaining basic tenant address information to pass to the <Tenant/> element within the Keyfax start-up data - this automatically passes the tenants address as defined within Dynamics to the Keyfax script.

Last updated