Disable a section on profile form on Dynamics 365 portal dynamically

At the moment I’am setting up a community portal, where it is planned that the users can register themselves.

The portal users should also be able to enter their company name.
To do this, I use the field “adx_organizationname” provided by the portal because with an account lookup everyone could see our customers. The backoffice then checks whether this contact is related to an existing company or a new one. As soon as the contact is then connected to an account record, the organization name should no longer be changeable by the portal user.

What not worked

  • Javscript on CRM form.
  • Business Rule on CRM form (because it is Javascript).
  • Add the field twice to the form to have one editable and one readonly and hide the the not applicable with jQuery in the portal.
    The same fiels two times on the profile form let the portal crash.
  • Make the field readonly on the CRM form and enable it in the portal with jQuery did not save the data back to CRM.

Solution

I have created a separate section for the company-related fields

Disable a section on profile form on Dynamics 365 portal

and make it readonly when parentcustomer is not empty.

Disable a section on profile form on Dynamics 365 portal

This creates following tag in the HTML structur.

Disable a section on profile form on Dynamics 365 portal

The result looks like this.

Disable a section on profile form on Dynamics 365 portal

Oh wait, happy times, Dynamics portals has arrived my blog for the firtst time!

 


Get isActivity from Metadata

This week I had to differentiate between normal entities and activities in Javascript. I had a look into the SDK and remembered my previous post “Get EntitySetName from Metadata“. A little modification and I get true or false from the ‘isActivity’ information in the metadata.

Here it is fo you: Get isActivity from Metadata

isActivity

 


CalculateRollupField with WebApi function in Javascript

Microsoft added with Service Pack 1 a new function called “CalculateRollupField” in Dynamics CRM (v 8.1) which enables us to recalculate a rollup field on demand.
I will show you here how you can use it in Javascript with a http request against the WebApi.

The CalculateRollupField function inside the webrequest needs a few parameter to know which rollup field you want to to calulate:

  • The EntitySetName of the target record.
    I wrote here how you can get the EntitySetName from the Metadata with an webrequest too.
  • The GUID of the target record.
  • The schema name of the target field.

CalculateRollupField in Javascript:

The answer of the webservice for the CalculateRollupField function contains the value for the target field, the date of the last calculation and its state.

CalculateRollupField Result

 


Get EntitySetName from Metadata

Everybody who has worked with the Web Api, in the system formerly known as Dynamics CRM (honestly, I do not know how to call it now), must have notice that you can’t pass the EntityLogicalName to it. It expects the EntitySetName, which is a kind of plural name for the entity.
Not to be confused with the plural display name you can configure in the entity.

So far I had a little Javascript function that tried to imitade the rules wich are responsible for the generation of the EntitySetName. But since there can be some exceptions, I’m now the opinion that it would be more reliable to query the metadata directly from the system.

Here it is: Get EntitySetName from Metadata

 


Export a solution via Javascript

Last week I got an error during a solution export, but the error message wasn’t very helpfull. I then had the idea to export the solution via Javascript with the hope to get an more meanfull error.
Fortunately it was so and by the way I’ve learned how to export a solution via Javascript.

 


How to load Javascript from a webresource

Imagine an usecase where you can dynamically load a Javascript from the CRM webresources because it doesn’t need to be loaded on every single form load. Perhaps a polyfill to add missing browser functions or a Javascript library like jQuery. Here it is…

My personal usecase was to add a promises polyfill to the Internet Explorer. So, if you combine this post, my post about “Internet Explorer and promises” and you have a promises polyfill in your CRM webresources, you can use promises and do only load the polyfill in case the browser doesn’t support it.

 


Limits for custom parameters

Have you ever asked how many characters you can pass as parameter to a Javascript event handler or to a HTML webresource? I do, because I like to give a consultant or the customer the possibility to pass dynamic values in form of JSON objects or even whole functions without touching my code.

HTML webresource

The limit here is at 1.500 characters.

Javascript event handler

I think there no limit. Really. I made a test with up to 2.400.000 characters without any problems. The only thing that I would mention – do not exaggerate it as I did, because the performance suffers quite a lot.

 


Internet Explorer and promises

Microsoft shows us on Get started with the Microsoft Dynamics 365 Web API (client-side JavaScript) how to create a re-usable function using promises. Between the description and the example is a little note box that points out that Internet Explorer 11 doesn’t implement native promises. Most other browsers support promises natively, IE is the problem child – again.
Microsoft further advises that there are several polyfills and libraries which will implement promises to IE. But they don’t tell you how do this in an effective way.

Detection

As you don’t want to add and load superfluous libraries, you have to detect if the browser has promises implemented. In my first approach I used modernizr. 2KB more just for detection. That is not what I wanted and searched for a plain js solution and found it at stackoverflow.

Agony of choice

Now that we can detect if the browser has implemented promises or not, which polyfill or library should we implement additional? My decision fellt on the smallest possible solution I found – ‘ES6 Promise polyfill’ with only 2KB.

 


Dynamics CRM Bookmarklets V2

About a half year ago, I’ve shared my Dynamics CRM Bookmarklets collection with you. Currently the collection has been reworked several times and the number of Dynamics CRM Bookmarklets Sammlung has been nearly doubled. I was influenced particularly with the new ideas for the bookmarklets by Jukka’s ‘CRM Navigation Hacking’ and Markus ‘Find Dependencies for Uninstalling Solutions’.

Compared to my first “Dynamics CRM bookmarklets” article, the display format has changed. Mainly because the implementation was not working clean as a hyperlink. In addition, some functions were still packed in an anonymous function.

Do you want to use one of bookmarklets, you just need to creat any bookmark in the bookmark toolbar of your browser and you change the URL to “javascript: (function () {…” and everything after the line comes from.

If you work with several browsers and want to your bookmarks synced in all of them I can recommend you Xmarks.

Updates!

  • 2017-09-21: added “open record by id”
  • 2017-09-21: updated “update view”
  • 2015-07-19: added “new solution” and “open default solution”
  • 2015-04-26: added “open perfomance center”
  • 2015-04-19: added “update view”
  • 2015-04-15: added “clear localStorage” and “clear seesionStorage”

Should you have own ideas or bookmarks that I have not covered here, you can send me them very gladly.

 


Pass parameters to HTML Webresource

A HTML webresource can not just only show HTML elements on your form, furthermore you can work with JavaScript in it and interact with your form. IF you want to access the Xrm namespace of the form inside your HTML webresource, you simply need prepend “window.parent” to your function call.

This looks like in this example:

If you need a lot of such calls, you can make your life easier and create your own local variable and assign it the complete Xrm namespace
This could look like this:

Pass parameters to HTML Webresource

Alternatively, you can also pass static values to your webresource. Just add a custom parameter in properties dialog of the webresource.

Pass parameters to HTML Webresource

You can access the custom and contaxt parameters with the following script inside your webresource:

The custom parameters should be in the form “Name=Value” should be separated by comma.

The debugger shows you all the accessible parameters:

Pass parameters to HTML Webresource

Context parameters are green marked, custom parameters blue.

You can now access your values through the named array.

Have fun with it!