Tag Archives: portals

Dynamics 365 portals: Use liquid to return JSON or XML

Gem of an article from Colin Vermander

{knowhow} How to refer a JavaScript file in your PowerApps/ Dynamics 365 Portal which is not accessible via public URL?

This is a big question I face whether I am conducting a training or whether I am working on PowerApps portal in customer location. And I am really not surprised.

Say you have a custom .js file where you have scripted some wonderful functions and want to reuse in the portal. It’s a really big file and you just want to reference it and start using. Not only that, there may be some external .js files which you may want and just use it. If it is some jquery or bootstrap, you can just use the CDN url to refer to the file. However what if it is something internal or not accessible on a publicly available URL.

The first option that comes to mind is upload the .js file using webfile. Can you do that? Off course you can do this. While this is possibility, the probability of .js file being allowed for upload is slim. Whenever you upload a web file, it is basically uploaded as note attachment in your CDS/ Dynamics 365 environment and more often that not, it is not comprehensive solution.

Below is the error I receive when I try to upload a .js file in webfile.

image

So what are we left with. You may think, the only other option is to upload the file on some public repository which can be accessed by the portal and then referencing the file using the script template in your webtemplate or Page copy. So much for so little.

Well there is another way. What if you could load the content of your javascript file at runtime? You guessed it right. We are going to to do the same stuff now.

Let’s go ahead and create a content snippet of type HTML

image

In the Value box, i select the HTML option and paste the entire content inside the javascript file within the script tag.

image

Easy – Isn’t it? Not so fast. Notice carefully the code above. The entire content including the script tag is included with {% raw %} {% endraw %} tag.

What is the function of this tag and why is this even necessary? The {% raw %} is absolute necessary to render the script as is when the snippet is used. Javascript contains liquid specific operators like curly braces ( { } ) % and so many other. If you don’t put them in the {% raw %} tag, it would try to evaluate while you try to use the snippet and your content shall never work.

Ok Good stuff! Now let’s use this snippet on a page.

Open the “Content Page” your webpage.

image

Scroll down and navigate to the Copy (HTML) section of the page. To include the script file, all you need to do is select the HTML tab and use the snippet we created in the earlier step.

image

Trust me that’s all. Now when the page is rendered in the portal, I see my entire JS Content being in the HTML source. Great to finally see it.

image 

Now let’s put this to action. In the custom javascript section of the Content Page, on change I write code to invoke func1();

image

And when I login to the portal and change the SIC code, I can see the alert firing. Wonderful isn’t it. A simple liquid tag and a quick workaround can sometime do wonders.

image

For multiple .JS files, you can create multiple snippets and refer it.

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:

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

Notes Manager (https://debajmecrm.com/2019/02/28/add-metadata-to-your-notes-and-attachments-in-dynamics-notes-metadata-manager-from-xrmforyou-com/)

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

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

Strip HTML characters using Liquid in PowerApps/ Dynamics 365 Portals

I have been working lately a lot on PowerApps portals and one of the requirement that we got from customer is to render some HTML text as text in Portals. The customer had a field in Dynamics 365 which was storing rich text.

We would retrieve the field value using fetchxml in liquid and the requirement was to strip the HTML characters and show the text in plain text. We did that initially in JS, only to realize later that there is a specific filter available in liquid – “strip_html”.

And guess what it worked like a charm.

Input:

{{ “<span>This liquid filter <b>can work wonders</b> with stripping HTML<br />” | strip_html}}

Output:

This liquid filter can work wonders with stripping HTML

As I am working more and more on liquid, I am simply falling in love with it. Simple yet quite powerful language. And as I keep exploring, I will post some interesting stuffs over the next few weeks.

Hopes 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:

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

Notes Manager (https://debajmecrm.com/2019/02/28/add-metadata-to-your-notes-and-attachments-in-dynamics-notes-metadata-manager-from-xrmforyou-com/)

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

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

Working with custom DateTime formats in PowerApps/ Dynamics 365 Portals

By default in PowerApps portals, the date and time is showed in the format as configured in CDS/ Dynamics 365. However you can override the default date/ time format to be used on portals with the below site settings.

  • DateTime/DateFormat: The date format used on the portal.
  • DateTime/TimeFormat: The time format used on the portal.
  • DateTime/DateTimeFormat: The format for full date and time used on the portal.

We have a requirement to display the date field in particular format such as 20-May-2020 in Power Apps Portals. This can be achieved by creating site setting in the below format.

Now let us create a site setting

Name – DateTime/DateFormat

Value – dd-MMM-yyyy

Screenshot for reference

clip_image002[4]

Once you clear your portal cache, you should see the date time values now reflected in the portal accordingly.

clip_image004[4]

It displays time as my date field is of type date-time format.  For the benefit of readers, sharing some other format which can be of help.

1. yyyy-MM-dd – 2020-05-16

2. MMM dd yy – May 13 20

3. dd/MM/yyyy – 27/05/2020

4. dd/MM/yyyy HH:mm – 14/05/2020 12:27

5. dd/MM/yyyy hh:mm:ss – 12/05/2020 12:30:52 – 12 Hour format

6. dd/MM/yyyy HH:mm:ss – 27/05/2020 19:32:02 -24 Hour format

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:

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

Notes Manager (https://debajmecrm.com/2019/02/28/add-metadata-to-your-notes-and-attachments-in-dynamics-notes-metadata-manager-from-xrmforyou-com/)

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

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

Could not find a part of the path … bin\roslyn\csc.exe. Error while setting up of OAuth implicit 2.0 API for PowerApps portal

IF you are not aware of OAuth 2.0 Implicit grant for PowerApps portal, I suggest you refer this Microsoft Docs link.

To put in Microsoft words –

“This feature allows a customer to make client-side calls to external APIs and secure them by using OAuth implicit grant flow. It provides an endpoint to obtain secure access tokens that will contain user identity information to be used by external APIs for authorization following OAuth 2.0 implicit grant flow. The identity information of a signed-in user is passed in a secured manner to the external AJAX calls. This will not only help developers to pass authentication context but will also help users to secure their APIs by using this mechanism”.

The docs link is pretty extensive to make your understand the various nuances of this concept. My blog talks about a specific issue which you may encounter when you try to download the sample API from this link – https://github.com/microsoft/PowerApps-Samples/tree/master/portals/ExternalWebApiConsumingPortalOAuthTokenSample and try to build the same.

When you build you may get the following error – Could not find a part of the path … bin\roslyn\csc.exe

Trust me if you are not aware on how to resolve this, you may waste significant time of the day in trying to build the project instead of getting it up and running the wonderful feature.

So basically there are two ways to resolve this.

Uninstall the Nuget packages

1. Microsoft.CodeDom.Providers.DotNetCompilerPlatform
2. Microsoft.Net.Compilers

After you do this, find references of compiler tag in your web.config

<system.codedom>
     <compilers>
       <compiler language=”c#;cs;csharp” extension=”.cs” type=”Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, ……….”></compiler>
       <compiler language=”vb;vbs;visualbasic;vbscript” …………></compiler>
     </compilers>
</system.codedom>

If you find this, simply delete it. This should get you up and running.

If you ask me, this is workaround and not really a good solution. This is because you can’t use the new compiler and new features. The other way is

copying file from “<your path>\packages\Microsoft.Net.Compilers.1.3.2\tools\csi.exe” to “bin\Debug\roslyn\csi.exe”. This is an easier and simple way to do it and your Sample API would be up and running.

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:

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

Notes Manager (https://debajmecrm.com/2019/02/28/add-metadata-to-your-notes-and-attachments-in-dynamics-notes-metadata-manager-from-xrmforyou-com/)

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

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


string to integer, string to decimal in liquid template–Is typecasting through liquid in PowerApps portals/ Dynamics 365 Portals adding to your woes? the type filter may just be you way out

First of all this is not specific to Dynamics 365/ PowerApps portals. However since I try to put everything related to my passion – dynamics 365 and PowerApps, I try to relate every blog post of mine with that.

Coming to the topic, this is related to liquid. And as the title say’s, it is related to typecasting.

Say you have string variable. And you want it to typecast to integer and perform some sum/ subtraction operations with it.

Let’s take this example.

{% assign num1 = “2” | plus: 10 %}

{% assign num2 = num1 | plus: 20 %}

{{ num2 }}

What do you expect num2 value? You may be expecting 32. But it will print 21020.

If you search the net, you will find workarounds like {% assign num1 = “2” | plus 0 %}. Unfortunately it won’t work as well.

So what is resolution? Liquid type filter comes to the rescue. The below code shall work just fine.

{% assign num1 = “2” | integer | plus: 10 %}

{% assign num2 = num1 | plus: 20 %}

{{ num2 }}

Now num2 will be printed with value 32.

The below type filters are supported

  • boolean
  • decimal
  • string
  • integer

In case the typecasting fails, it is always suggested to use the default filter to specify the default value in case of failure

For example – {{ “blah blah” | boolean | default: false }}. It is obvious that typecasting for this shall fail. So the output would be default value specified which is false.

This is even very useful where you are working with query strings. Query string value will always be in string format. So you would need to typecast them in the type you want.

For example – {% assign increment_value = request.params[‘increment_value’] | integer %}

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)

Automatically sign-in with Azure AD in PowerApps/ Dynamics 365 Portals on Sign in click.

Recently I had this requirement where the customer wanted to automatically sign in using the default Azure AD option on clicking Sing in the header menu in PowerApps portals.

image

So when the Sign In link is clicked, the user should be automatically signed in without being redirected to the Sign In page and then clicking on the Azure AD button.

It’s actually quite easy to do the same. And it can be accomplished using couple of site settings.

The first site setting is Authentication/Registration/LoginButtonAuthenticationType. To set the value of the site setting, we need to get the GUID of the identified.

Click on Azure AD button. And copy the URL from browser where you are being redirected to. The URL shall be in the format as shown in the below screenshot.

image

Take the first guid after login.microsoftonline.com and use this value for the previously mentioned setting. The value will be in the format – https://login.windows.net/<guid>/.

image

Don’t forget to put the trailing slash after the GUID.

The next step is to basically check for another site setting – Authentication/Registration/ExternalLoginEnabled. If this site setting is not there, it’s fine. If it is there, set it to False or disable it.

Make sure you refresh the portal cache. Sometimes, to reflect authentication related settings, you may need to restart the portal as well to reflect it immediately.

Now once the user clicks on Sign in link, it automatically signs the user in with Azure AD.

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)