Development, Troubleshooting

Xrm.Utility.lookupObjects: Episode 3: The UCI strikes back

Today was the last day of the North America UGSummit. It was my 3rd UGSummit and I’m already prepared to pack my bags to travel to next year’s UGSummit in Nashville, TN. I like it a lot for many reasons – reconnecting with my MVP Family, thought-provoking sessions, networking, and the “CRMUG Medics” booth. For those who don’t know what the “CRMUG Medics” booth is, just imagine a place where you can go and ask questions you have about development, administration or troubleshooting e.t.c. and that booth almost always has a couple of MVPs that are ready to answer your questions. I really enjoy helping others by answering their questions, so I was hanging out trying to help visitors and I got asked a question:
“In our code we used Xrm.Utility.lookupObjects with additional filters. When we are running the scenario in the Classic Interface everything works fine, but it doesn’t work in UCI. What can I do to make the code work in both interfaces?”

I recalled that I wrote a post about Xrm.Utility.lookupObjects function almost 2 years ago when 9.0 was just shipped. I opened the post quickly and compared their code with what I had written in my post. It looked really similar to what I had. Let’s say it was following:

After that, I recalled that I saw the post in the community forum that code works for Classic Interface but doesn’t work in UCI, but I was busy with my project tasks and had no time to troubleshoot so I put that idea aside and forgot about it. Until that same question appeared during the UGSummit.

To assure myself that the code was still valid, I went to the doc.microsoft.com page that describes this method and I discovered that a couple of the new properties were introduced but the most intriguing was the “filter” property. Here is the screenshot from the official documentation:

That was exactly what had to be used! So I suggested to them to rework the code in the following way:

The code was refactored, then published, and everything worked fine in UCI, but at the same time stopped working in the Classic Interface.

To make the code function properly again in both interfaces, I suggested to combine both pieces of the code and, depending on the type of the UI used, pass the configuration of the filter that worked for the particular interface. This code uses an undocumented function for detection of the interface type, so please take it in consideration if you want to use that approach or not:

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.