“File” data type in CDS. All you may need to know about it.

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com

Well this one is pure serendipity. I was working for a customer and while creating a new field for an entity, I could see a new data type called – “File”.

image

Honestly I haven’t heard of any announcement regarding this data type before and I was quite intrigued about what it is this data type. So I decided to dig deeper.

As I was trying from the classic solutions area, I decided to move on to the solutions area in PowerApps maker portal and check if that data type is showing up. And it indeed shows up.

image

As Microsoft is recommending, you should be using PowerApps maker portal more often than not. And the reason is there are some stuffs which you can only perform in maker portal and not is classic solutions area.

In the powerapps portal, you can set the size of the field. By default, the upload size is 32 MB. However you can set it to a max of 128 MB.

Few more basic info before I dive deep.

Is this available for all OOB and custom entities?

Yes.

Can we have more than one field of type “File”?

Yes.

Very well. And now comes the awesome news. When this field was introduced it was not available for Model driven apps. That was a big disappointment. But now the field can be included in Canvas apps, flows and model driven apps as well. Below is the screenshot of file data type in canvas app. And it works like a charm

image

I wonder whether it will be ever exposed to the Model driven apps and if yes, I think it completely changes the dynamics of file storage in CDS. Suddenly you have an ace to play with outside Notes and SharePoint integration.

Well well, this is nice. But how about getting the data stored in these fields. As coding is my forte, I am always bit biased towards developers and here I am not let them high and dry.

Detailed information is provided in docs – https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/file-attributes

In the docs link, there is sample code to query using REST API. Although the class for querying using .NET SDK is mentioned, there is no sample code on how to download the file bytes using the same. Hence I thought of putting this sample code for the benefit of readers.

InitializeFileBlocksDownloadRequest initializeFile = new InitializeFileBlocksDownloadRequest(); 
            initializeFile.FileAttributeName = "cr269_filedatatype"; // attribute name 
            initializeFile.Target = new EntityReference("account", Guid.Parse("37F480BE-EA1F-EA11-A810-000D3A569DFF"));

            InitializeFileBlocksDownloadResponse initializeFileResponse = (InitializeFileBlocksDownloadResponse)service.Execute(initializeFile);

            Console.WriteLine($"File Name: {initializeFileResponse.FileName}"); 
             Console.WriteLine($"File size (bytes): {initializeFileResponse.FileSizeInBytes}");

            var fileContinuationToken = initializeFileResponse.FileContinuationToken;

            // code to downlod the file. 
            DownloadBlockRequest downloadRequest = new DownloadBlockRequest(); 
            downloadRequest.Offset = 0; 
            downloadRequest.BlockLength = (long)4 * 1024 * 1024; // can be max of 4 MB 
            downloadRequest.FileContinuationToken = fileContinuationToken;

            DownloadBlockResponse downloadBlockResponse = (DownloadBlockResponse)service.Execute(downloadRequest);

            byte[] fileBytes = downloadBlockResponse.Data;

Couple of important points with the above code. You can download a max of 16 MB in one call. For the remaining content you need to query again using the FileContinutationToken. The block size determines the maximum chunk that can be retrieved in further calls. The file bytes cannot be retrieved using RetrieveRequest or RetrieveMultipleRequest

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)

{Know How} Apply Business process flow on create of a record or skip setting of default Process flow based on custom business logic in Dynamics 365 using ProcessId field of record

Business Process flows are used everywhere and as a Power platform consultant you might be working with them almost everyday.

However sometimes the intricacies of the most mundane stuffs seems to baffle us. And one of them is was this requirement that I recently had. And trust me I found many was not aware of the solution.

So the customer here wanted to apply Business process flow to a record based on some business logic. Let’s understand the full requirement first before I go ahead with the solution.

So the customer have field on Account entity. Let’s say field name is “BPF Indicator”. It’s an option set field. And let’s assume there are three values for this field.

  1. Value 1
  2. Value 2
  3. Value 3

There are three BPF’s for Account. So basically the logic goes like this.

  1. If account is created with Value 1, then BPF 1 should be applied
  2. If account is created with Value 2, then BPF 2 should be applied
  3. If account is created with Value 3, then BPF 3 should be applied.
  4. If no value is selected, setting BPF for the record should be skipped.

The accounts could be created through integration, data import and also admin can set it up from UI.

Of the three Business Process Flows enabled for account entity, BPF1 was the highest in order. So it is kind of default Process flow for account.

What we did initially was to use the SetProcessRequest in our plugin to set the appropriate BPF. But what is the problem with that? The main issue with that is the process instance for the default Business process flow which in this case is BPF 1 was also getting created.

Say an account named “Account 1” is created with “BPF Indicator” = Value 2. We were using SetProcessRequest method to set BPF 2 for account record. But when we checked Advanced find, we found that two process instance records for Account 1 got created. One for BPF 1 which is the default one and the other for BPF 2.

So how do we remove the default process for being applied at all. A lot of searching but trust me it’s again docs which came to my rescue. Link below:

https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/model-business-process-flows#apply-business-process-flow-while-creating-an-entity-record

So the gist is to make use of the ProcessId field of the record. Surprisingly while the field is deprecated, it is still the deciding factor while setting the BPF for a record. All I did was to create a plugin on pre-operation stage of account create and set the appropriate value of processid.

So if I need to set the BPF as BPF 2, all I need to do is set the process id field to the value of process guid for BPF 2. If you don’t want to apply BPF for a record, you would need to just set is as Guid.Empty.

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)

Continuous Integration, Deployment & Test Automation for Dynamics 365 CE in Azure DevOps/VSTS – Part 1

One of the most comprehensive articles on Azure DevOps integration & Dynamics 365. Blog series consisting of 3 articles which describe the process end-end

Power Platform/Dynamics 365 CE/DevOps Blog

In this blog series, we will explore building out DevOps processes and
practices for Dynamics 365 Customer Engagement (CE) by utilizing Wael Hamez
MSCRM Build tools. In this first blog, we will cover the version control for
Solutions.

What is
DevOps?

DevOps is a new term emerging from the collision of two major related
trends. The first was also called “agile infrastructure” or “agile
operations”; it sprang from applying Agile and Lean approaches to operations
work.  The second is a much-expanded understanding of the value of
collaboration between development and operations staff throughout all stages of
the development lifecycle when creating and operating a service, and how
important operations has become in our increasingly service-oriented world (cf.
Operations: The New Secret Sauce).

Problem
Statement

I have started working on CI/CD when I was assigned as a Platform
Engineer for a Dynamics 365 CE implementation project. At that time, I had a…

View original post 1,539 more words