Fetch XML Archives - Aric Levin's Digital Transformation Blog http://aric.isite.dev/tag/fetch-xml/ Microsoft Dynamics 365, Power Platform and Azure Thu, 12 May 2022 03:14:50 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.3 Implementing Feature Flags for Power Apps deployment http://aric.isite.dev/dynamics/post/feature-flags-powerapps-deployment/ Sat, 07 Mar 2020 00:30:00 +0000 https://aric.isite.dev/index.php/2020/03/07/implementing-feature-flags-for-power-apps-deployment/ I am current engaged in a project where a vendor suggested to the customer to use the same entity for various purposes. That decision might have worked for some organizations, but it did not have a foresight of the future requirements of the organization.

The post Implementing Feature Flags for Power Apps deployment appeared first on Aric Levin's Digital Transformation Blog.

]]>
I am current engaged in a project where a vendor suggested to the customer to use the same entity for various purposes. That decision might have worked for some organizations, but it did not have a foresight of the future requirements of the organization.

Moving forward a couple of years, we finally have the bandwidth to go ahead and split this into a couple of entities. The only issue with this is that the amount of work is substantial, and at the same time we need to continue developing other processes and deploying enhancements and bug fixes across our higher environments.
In the past, while working on custom software projects, we recently had the need to use Feature Toggles (also referred to as Feature Flags). Feature Flags are used in many places for preview features, experimental toggles, A/B testing, permissions toggles and other toggles that you might encounter.
Feature Flags allows the developer team to modify system behavior without changing code. The solution would reach the code that it needs to execute, and based on the Toggle, would select to go via route A or route B. An example of this would be a process that sends an Invoice to and end user. The company address is changing, and we have two versions of this invoice. We add a feature toggle that specifies whether to use the new address or the old address. When the company moves, all that has to be done is change the toggle, and from that point on, only the new Invoices will be printed.
In order to implement this in our Power App, we first need to create a couple of entities to store the data, or the features. The first entity will be called the Feature Flag, and the second entity is an optional entity which will be called Feature Access.
The Feature Flag entity will basically contain a name for the feature, and a two options field to determine whether the feature is active or not (basically use Option 1 or 2). We can also just use the Status of Active or Inactive.

Feature Flag Entity

In our case, we sometimes want features to be available to a subset of users (for testing purposes or partial access). The Feature Access entity has a relationship between the Feature Flag and a User or Team (Owner).

When the Feature Flag is enabled for partial access based on the Feature Access entity, the application will check whether or not a user or a user that is a member of a team have access to a particular feature. If they do, it will show the new version of the feature, if they don’t it will show the previous version of the default option.

Feature Access Entity

In order to implement this, we had to add logic code for our Plugins and our Scripts. We also added a Custom Workflow Activity that would help us control the flow within our workflows. The same, of course could be done with Power Automate flows if required.
Let’s take a look at the custom code. Our plugin code, simply reads the combined data between both entities using a fetchXml statement and returns a value of true or false determining if the user has access to the new feature.

Feature Flag C# Code

The javascript code does the same and also calls the Xrm.WebApi and uses a fetchXml statement to retrieve a boolean value.

Feature Flag JavaScript Code

Source code for this post is available on Github. Make sure that the variable names in the code match the entity names.

The post Implementing Feature Flags for Power Apps deployment appeared first on Aric Levin's Digital Transformation Blog.

]]>
Multiple Fetch Xml Statements with Or Filter in Portal Web Template http://aric.isite.dev/dynamics/post/multiple-fetch-xml-or-filter-portal/ Wed, 16 May 2018 06:22:00 +0000 https://aric.isite.dev/index.php/2018/05/16/multiple-fetch-xml-statements-with-or-filter-in-portal-web-template/ In a recent project, we had a requirement to display cases to the portal that are associated with either Contacts or Accounts. Our case entity had a related entity called Case Contacts, and our account entity had a related entity called Account Contacts. The account entity had a list of all the cases associated with the account.

The post Multiple Fetch Xml Statements with Or Filter in Portal Web Template appeared first on Aric Levin's Digital Transformation Blog.

]]>
In a recent project, we had a requirement to display cases to the portal that are associated with either Contacts or Accounts. Our case entity had a related entity called Case Contacts, and our account entity had a related entity called Account Contacts. The account entity had a list of all the cases associated with the account.

The issue that we had was that we could retrieve each list of cases individually, but the result could be duplicate where a case could be associated with both a Case Contact and an Account Contact.

We were struggling on whether to retrieve the first fetch, and then the second fetch and check the values that were part of the second fetch didn’t appear in the list of first fetches, or the alternative was to have a single fetch Xml that contained both conditions with an Or Condition in-between. The issue here is that advanced find does not allow created an Or condition with related entities.

Thanks to a post by Alex Shlega, we were able to do this easily. This can be done using XRMToolbox Fetch Xml Builder or just writing the Fetch Directly in a Text editing tool. The end result that we had was the following:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >
  <entity name="incident" >
    <attribute name="incidentid" />
    <attribute name="title" />
    <attribute name="customerid" />
    <attribute name="xrm_businessname" />
    <attribute name="statecode" />
    <attribute name="statuscode" />
    <filter type="or" >
      <condition entityname="ad" attribute="xrm_contactid" operator="eq" value="{{user.id}}" />
      <condition entityname="ab" attribute="xrm_contactid" operator="eq" value="{{user.id}}" />
    </filter>
    <link-entity name="account" from="accountid" to="customerid" link-type="outer" alias="ac" >
      <link-entity name="xrm_accountcontact" from="xrm_accountid" to="accountid" link-type="outer" alias="ad" >
      </link-entity>
    </link-entity>
    <link-entity name="xrm_casecontact" from="xrm_caseid" to="incidentid" link-type="outer" alias="ab" />
  </entity>
</fetch>

By adding the entity names to the Or Filter, we are able to specify conditions for the linked entities, and by doing this filter multiple linked entities with an Or Condition.

This resolves the issue of having to deal with duplicates in the results or having multiple result sets from separate Xml statements.

The post Multiple Fetch Xml Statements with Or Filter in Portal Web Template appeared first on Aric Levin's Digital Transformation Blog.

]]>
Fetch Xml Portal page with Entity Permissions http://aric.isite.dev/dynamics/post/fetchxml-portal-entity-permissions/ Sun, 29 Apr 2018 18:20:00 +0000 https://aric.isite.dev/index.php/2018/04/29/fetch-xml-portal-page-with-entity-permissions/ Recently we had a requirement for one of our Dynamics Portal projects that I thought we could share with the community. The requirement was pretty simple. We had a many to many relationships between Contact and Account (so that a contact could belong to multiple Organizations) that needed to be displayed in a dashboard.

The post Fetch Xml Portal page with Entity Permissions appeared first on Aric Levin's Digital Transformation Blog.

]]>
Recently we had a requirement for one of our Dynamics Portal projects that I thought we could share with the community. The requirement was pretty simple. We had a many to many relationships between Contact and Account (so that a contact could belong to multiple Organizations) that needed to be displayed in a dashboard.

The default out of the box relationship for Account of the Contact having a Scope of Contact, or even a Scope of account did not work, so we needed to set a Global Scope, basically exposing this to the Portal, but limiting what will be available using our own logic.

The image below shows the Entity Permission that we set, so that it would become global:

Entity Permissions

The next step that was needed was to design the fetchXml to retrieve all the accounts that are associated the portal logged in user. We needed to use the user.id liquid object. We created a Web Template that contained the following Xml. This would retrieve a list of all accounts that are associated with the Account Contact many to many manual entity, and display it on the Web page.

The first part of the web template, which includes the fetchXml is shown below. Notice the link-entity which contains the relationship between account and contact and the condition attribute set to the logged in user id.

Fetch Xml in Liquid

The next part is retrieving all the accounts (if available). We loop through the list of accounts and display the account name, and other fields.

Looping through FetchXml Results

Finally, we can create a new web page based on a web/page template to view the results is our web portal.

Fetch Xml Results

The post Fetch Xml Portal page with Entity Permissions appeared first on Aric Levin's Digital Transformation Blog.

]]>