Client API – lookupObjects

clientapi-xrmmodel

New Client API

Lately, I’m exploring Client API that came with Dynamics 365 v9.0 and I can tell you that it has a bunch of cool stuff that is not used that frequently by the Dynamics community.

My top 3 namespaces are:

  • Xrm.Navigation (alert and confirm dialogs)
  • Xrm.Panel (side panel that makes some integrations look seamless)
  • Xrm.Utility (a bunch of new things)

In this post, I will show you one use case of a feature that made me so happy, because I always had a struggle when I tried to make look & feel of Dynamics lookup fields in my custom web resources.

This feature is of course Xrm.Utility.lookupObjects

The struggle

Every time I wanted to use lookup input field in my custom web resources I had the same problem. Which kind of control to use to present the lookup input field?

Sometimes I went the autocomplete route, but I had problems with validating the wrong values (user searched something and left the value that was not found in the textbox) or I went the dropdown route which was not that good option because it lacks a search option, but it forces user to choose the right value.

Solution

New API call Xrm.Utility.lookupObjects solved my problem and saved me some (BIG) amount of time. That new function allows you to open lookup browser with entities that you want to search for and returns the object containing record GUID, entity type of the record and a name of the record.

Example

My goal was to create a simple example that will display what you can do with the new function.

The goal is to create a popup window on a contact entity that will allow you to pick some system user in the popup and initiate a task entity creation that will have picked user as the owner of the task and the current contact in the regarding field.

I hope that example is simple enough to show you everything that is relevant while using this function.

Before we start making the solution I wanted to note that I really like Alert.js solution that makes popup windows in Dynamics so much easier. It has some downsides of course, but for the most challenges, it does a great job.

First, we need to make a simple HTML web resource that will be popped up. HTML code is shown in the code box below.

After we have created the HTML file we need to create a JS file that will invoke the actual logic.

There are 2 functions that are interesting here:

  • openLookupDialog
  • populateLookupValue

Function openLookupDialog is called when the user focuses the input element with name ID and it opens the lookup dialog.

There are few parameters that we need to pass to the openLookupDialog function.

Parameters:

  • entityTypes – list of strings containing entity names
  • defaultEntityType – string value of default entity
  • allowMultiSelect – bool value that controls multiple select

This is a minimum set of parameters that you need to pass to make this function work, but there are also other parameters that are mentioned in the official docs page.

The second function is populateLookupValue function that is called as success callback in the previous function. The parameter that is passed into this callback is a list of entities selected in the lookup dialog, but in our case, it returns only a single value because allowMultiSelect is set to false.

Each object inside that list has 3 values: id, name and typename which can be used in data operations after selection.

We use those values (or just a ID part) to create a task after valid record is selected.

Finally when we have the HTML and JS sorted we can add some CSS to get a Dynamics look and feel.

 

After everything is done right we can test our code and see the result. The result is shown in the next 3 steps.

STEP 1

Image 292

STEP 2

Image 293.png

STEP 3

Image 294

Conclusion

I hope that this example will help you when you will face the problem with using lookups in your custom web resources and as you can see it’s not that complex to use the new lookupObjects function in your solutions.

I like this function a lot because it gives the users similar UX as they are used to while using Dynamics.

Error while trying to connect to D365 v9.x via console app

question_mark_png57Lately, I noticed that I started to get errors while trying to connect v9.x organizations via console applications that were using OrganizationServiceProxy. Everything was set up just as it was usually working, but with new SDK it seems that it’s not.

The code below was just not working with all the right parameters sent to the constructor

Image 266.png

Here is the error that was popping out:

'Metadata contains a reference that cannot be resolved: 'https://.crm.dynamics.com/XRMServices/2011/Organization.svc?wsdl&sdkversion=90'.'

After a research and downloading the Microsoft.CrmSdk.CoreAsseblies NuGget package nothing useful was found, but since new versions of D365 Online have a support for .NET v4.6 framework I have updated my project to that version of the framework.

Since then error mentioned above was not present anymore while using Visual Studio 2017. I hope that this info will save you some time you will face the issue above.

TLDR: Update your console app project to .NET Framework v4.6!

Some emails are not synced to D365

sync-fail.png

Dynamics 365 and Exchange integration is plug & play with some minor configuration…I just don’t think so.

Lately, I had an issue that emails were not syncing to the Dynamics 365 using Exchange server via server-side synchronization. We spent like a month of intense monitoring and changing every single parameter in hope that emails will finally get synced without any issue.

Here are some of the tips that we used on our journey which finally made our integration work flawlessly.


Update to the latest Dynamics 365 version

The most basic thing to do is to update to the latest release of Dynamics 365, but of course, I know that it’s not always the best option and most people out there are considering it as the last option if everything else fails.

Image 233

Just trust me that more than few times I regret that I didn’t do an update first before I used too many hours of researching the issue.

Microsoft is adding tons of updated/hotfixes with every release that are not mentioned in the release notes. Last few versions had quite some updates related to the server-side sync mentioned in the notes.

The same email address on multiple entities

You should not use one email address on multiple OOB entities. It doesn’t matter if you are using it on 2 same records like contact entities for example or you just use it on 2 different records like on one user entity and one contact entity.

Image 235

You need to ensure that you just have one record on the instance that has a unique email address that is populated in the OOB email field (eg. emailaddress1,emailaddress2,..).

Syncing same email address on 2 instances

You can forget to disable email sync on the development instance when you finally move your email integration to the production instance.

The first step is to remove server profile from the mailbox on the development instance. Go to the mailbox that you want to sync on production, clear the server profile field and hit save button.

Image 240.png

The next step you need to do it test & enable the same mailbox on the production instance, but you need to be sure that you select the Sync items with Exchange from this CRM org only  checkbox on this step.

Image 239

After those steps, you are sure that emails will be synced only to the production instance.

Change mailbox ownership

The most strange tip is to change ownership of the mailbox form the TEAM to the USER.

Image 241

I know that this sounds ridiculous, but it actually helps in some situations. We came to this solution after talking to MS support that after a while suggested doing so and after that everything just started working like a charm.


I just hope that some of this tips will save you some time while investigating the syncing issue like this one.

Downgrade v9.0 trial

economy-downgrade-1

I recently discovered that you can downgrade D365 v9.0 to earlier versions like v8.2 or even v8.1. Also, I noticed that others around me didn’t know that it’s possible to do so and few of us had a need to test or develop something on earlier versions of D365.

Here are the basic steps how to accomplish that downgrade.

  1. Create a new trial D365 instance and go to Administration center.
  2. Click on the Edit button on your trial instance.Image 228.png
  3. Change instance type to Sandbox and click on Next.Image 229
  4. Click Save on the next screen.Image 230.png
  5. Next step is to click Reset on your newly created sandbox instance.Image 231.png
  6. Finally, in this step, you can select the earlier D365 version from the dropdown menu.Image 232.png
  7. After a rather long wait, you can turn your instance back to production one like we did in steps 2 and 3 and you are ready to do whatever you want on your fresh pre-9.0 version of D365.

It’s great opportunity to assemble a pre-9.0 solution on a trial instance if you don’t want to mess your other instances. I can’t explain how happy I was when I found out that I can have a pre-9.0 trial instance which can serve me as a playground for creating managed solutions.

I just hope that I’m not the only one that didn’t know about this downgrade thing and that at least someone will be happy with this feature as much as I was when I found it out.

Fight your randomly unpublished duplication rules

duplicate-content-image

If you ever used duplicate rules in Dynamics CRM you probably experienced that your rules unpublish randomly. That’s not 100% random because it’s only triggered when you import and publish the unmanaged solution, but it’s not done every time.

The action that triggers this is Publish All Customization that you invoke every time you import unmanaged solution to the CRM.

I made an managed solution to make your life easier by automating the republishing unpublished duplication rules after those rules are unpublished by Publish All Customization action.

You can find solution on the link. Solution is easy to configure and you will be able to use it in just few minutes after initial configuration.

overview

Check it on GitHub

After initial configuration you just need to select which rules you want to be automatically republished.

Avoid white space placeholder when hiding sub grid from entity form

Did you ever have a request to hide sub grids from entity form to keep it cleaner in some cases (eg. hide all empty sub grids)? The problem with this one is that if you just hide a sub grid it will still be shown as white space on the form and that’s probably not the way you want to do it.

The solution for this issue is to put each sub grid into a new section that will contain only one sub grid.

Below is an example how to hide all empty sub grids on entity form.

Hide all empty sub grids example

Place sub grid in a section element on form

First, you need to open “Form” editor and put each sub grid that you want to hide in separate section element. Grids that are supposed to be shown in all cases can remain positioned as usual.

Image 149.png

Upload JS file to Web Resources

Add new JS file Web Resource with the code shown below:

Add JS function for hiding sub grids on OnLoad event

You need to open “Form Properties” window and start adding stuff. Firstly you need to add JS file on the form (steps 1 and 2). After that, you need to set Control to Form and Event to OnLoad  (step 3). Finally, you need to add OnLoad event by pressing plus sign and set Library to JS file you added in the first 2 steps and name of the function from the JS file (in this example name of the function is hideEmptySubgrids).

Image 150.png

Final result

Image 151.png

Image 152.png

Ribbon suddenly​ disappears. What to do?

“My ribbon suddenly disappeared! Fix it as soon as possible.” -Angry Customer

If you spent your time customizing the ribbons on your entities you probably faced this issue, but there are not so many threads on the Web that are explaining this issue.

Most of the suggestions out there pointing you in the wrong direction, but will probably not lead you to the successful solution.

The answer is so simple and if you ask me very stupid. Your problem in the most cases will be just one field that you fill on button properties in your Ribbon Workbench. Maybe most of you had a dumb habit to copy-paste button label to most of the label/description/tooltip fields and thought that it’s the fastest and the best solution when creating the new button on the ribbon, but that’s what caused the issue.

ribbon_wb_stop

The key to success is in the “Tool Tip Desciption” text field that is probably filled by accident of just for a no clear reason. When you remove all the characters that you entered in this field your ribbon will not disappear anymore and from now on you will never fill every single field that you thought will be nice to not leave empty.

Tip of the day after you had this issue will be to keep the things as simple and as stupid as they are in general, you don’t need to fill every single field in there only because you think it will be much better that way. Think every time before you enter some information do you really need to type it or will it really help users in general.

P.S. Most of the users will never read your tooltips so don’t type in the description for it 😀