Tip #378: Using Calculated Fields To Work Around Field Restrictions

Free book idea for aspiring CRM authors out there: “1001 uses for calculated fields.” (We’ve already written a few, you can take this one).

I’m continually amazed by the novel uses for calculated fields that go beyond the obvious uses. Latest example–working around crazy field limitations.

Consider the following example: We have an opportunity configuration where the estimated revenue is the total of the opportunity product plus the value of a couple of fields from the opportunity record. We have a plugin that handles the calculation, so we do not want the estimated revenue field to be “system calculated.” All good, except there is no way to make the estimated revenue field in CRM read only when the opportunity is set to “user provided.” Even if you set the field properties to “read only,” or you create a business rule to lock the field, the system form scripts will set the estimated revenue field to editable when the opportunity revenue is set to user provided.

Enter calculated fields.

I created a calculated field and called it Estimated Revenue Display. I set the calculation action to the value of the estimated revenue field.

Then, I put the calculated field on the opportunity form right next to the Estimated Revenue field. I edited the form field properties and changed the label to “Estimated Revenue.”

Then I set the properties of the Estimated Revenue field to not be visible.

The result is a read-only user provided Estimated Revenue field.

Tip #377: Case for a rollup field

¡Hola, amigos! Like if we did not have enough of Spanish at the eXtremeCRM Madrid 2015, we have Pablo “CRMGamified” Peralta in da houz with another spicy tip!

How to setup the new rollup fields to count the number of cases associated with a contract line

Hello,

In this article I will explain step by step a concrete example of usage of the new rollup fields in CRM 2015, which is to count the number of cases associated with a contract line.

Brief introduction

In Dynamics CRM, we have different types of contract templates depending on their allotment type:
Contracts and allotments

  • Number of cases: entitles the customer to care for x number of cases
  • Time: the customer is entitled to x hours of attention (eg up to 10 hours of support.)
  • Coverage dates: the customer is entitled to unlimited attention given date range.

This is how a contract made with the “Number of cases” template looks like with its lines, including its respective allotments used (in the example, the customer has received attention to 145 cases under that contract line)

The problem with Coverage dates contracts and why the new rollup fields are so useful is…

.. that Allotments Used field remains in 0 (zero), it isn’t updated when allotment type = converage dates.

Therefore, it is an excellent setting where to apply the new rollups fields :), to roll up the total number of cases handled under that contract line.

Let see how to do this.
Continue reading

Tip #376: Stay with the versions

Andre “I’ve got 88 in my handle” Margono reports from the development trenches:

Based on the recommended practice to get the latest assemblies of Dynamics CRM SDK through Nuget I encountered one problem when I recently working on a demo with a CRM online instance.

Tipp Jarr: the problem Andre has encountered is that when you have a good old project and pull the latest CRM assemblies via Nuget
Latest CRM Assemblies on Nuget
then chances are you will receive the following (misleading) errors when building the project:

The type or namespace name ‘Xrm’ does not exist in the namespace ‘Microsoft’ (are you missing an assembly reference?)

What it means is that your project is compiled using Target framework 4.5.1 or earlier while latest CRM SDK wants at least 4.5.2.

As Andre continues:

As I’m still using Visual Studio 2012 (due to limitation of Developer Toolkit that currently supports up to VS 2012), I haven’t installed .Net framework 4.5.2 that required by the latest SDK v.7.0.0.1. Once I applied the .Net 4.5.2 update (developer pack version – t.j.), I get back with the development activities.

Tipp Jarr’s double-dip

And this is the perfect opportunity to observe chocolatey in action while you’re having a cup of beverage of your choice. Repeat after me: clist netfx-4.5.2-devpack.

Tip #375: Rolling in cash

Dynamics CRM TipperMini truck stop.

Finally, something exciting to discuss – money!

Today’s Roles

The Self-Healer: Jerry “I’m still in Kansas” Weinstock
For The Affirmative: Mitch “Snapshot” Milam

The problem, by Jerry

I have two rollup fields on a form – one for decimal and the other for currency – both pulling from the same child entity.

The currency rollup won’t display a value.

If I make a change to a field and save or just view the record and then go back to the grid view, no error message. However, if I refresh either calculated field I get this error when I navigate from the form:

<Message>’timeToString’ is undefined</Message>

It is on 7.0.1.121

Self-healing Solution, by Jerry

We finally figured out the issue. The distractor for us was that the error message <Message>’timeToString’ is undefined</Message> didn’t help us.

Side note – blah-blah, winge-winge (sensored – by t.j.)

How did this happen?

  • Import data into child records with currency data fields.
  • Create Currency Rollup field on Parent Record
  • Error gets thrown because child records don’t know what currency they are and the rollup process doesn’t like that. Child records are still happy.

Fix – set transactioncurrencyid for the imported records.

Is this a bug or is it behaving as expected?

Affirmation, by Mitch

That is to be expected.

Any time you have a currency field you must also have a currency added to the record. Without that, it does not know how to display the currency.

Normally, through the UI, this field is automatically populated but if creating records programmatically, you must always ensure that the transactioncurrencyid is populated. Import would be just another programmatic access method.

Good blog post there… (so here it is – t.j.)

Tip #374: NOT IN for the rest of us

Those with black belt in XML are familiar with the technique of building a FetchXML expression for NOT IN clause (e.g. accounts with no activities) and then sneaking that XML into a view definition to create non-editable view that returns the desired results.

What about the rest of us who don’t have the skillz or guts to edit customization.xml file?

  • Add a rollup field that counts the child records
  • Build a view that returns records where this field is zero

It’s not a real-time condition but is simple to build and use. In addition, the counter can be used as a quick visual indicator on the form itself if, for example, child records are not in the readily available subgrid.

Note: This tip was actually produced by Joel but since he’s too buzy or lazy to put this in writing, I’m taking all the credit.

Tip #373: Careful with delete button

As it turns out, Spießrutenlaufen is no longer exclusive developers domain and can be equally applied to the customizers. Shan “Smoke ’em” McArthur reminded all of us (and not for the first time) that it’s not all unicorns and rainbows with managed solutions.

If you ever delete a form for the entity that is part of a managed solution, you will lose that form forever.

he warned the audience.

No matter what you do, no solutions file gymnastics will resurrect the form (apart, of course, from uninstalling the entire solution and importing back the one with the form). At the same time, for unmanaged components, you can just simply reimport the entity with that form included and, presto, the form is back.

he continued.

Hear you. At least in the development world we can switch to one of the earlier commits. I’m glad that now developers have someone to share their appetite for the destructive behavior with.

Tip #372: IIS in the middle

Ages ago we had a tip on how to apply IP restrictions to your IFD CRM on-premises deployment. Traditional “this is unsupported” disclaimer followed. There is a way, however, to make it a) supported and b) infinitely more flexible and useful.

Enter Application Request Routing. Basically, the idea is to put a small IIS server as your “front” web server and then use ARR to route requests to the “backend” web server. In this configuration your “front” server does not need to have any CRM components installed at all as its sole purpose is to route requests.

Steps

  1. Configure default web site to listen on 443 with your IFD certificate
  2. Install ARR
  3. Create a server farm in Application Request Routing and add your CRM server to it
  4. Check that proxy is set to passthrough
  5. Make sure external CRM requests are going from your firewall to your “front” server

Well, that was easy. Now, you can

  • Apply IP filtering by tweaking web.config on your “front” server. Since we are not touching CRM installation, we are on the supported side.
  • Add more CRM web servers to the farm and do load balancing that is more flexible than NLB (network load balancing), traditionally used with CRM web servers.
  • Configure URL rewrite and introduce vanity URL for your deployment, e.g. make your internal and external URLs the same; this has been done before but now we are supported as we are not touching CRM servers.
  • Anything else?

Tip #371: Use your fingers

Here, at eXtremeCRM 2015 Madrid, my good friend Gustaf (not V) Westerlund and I had a privilege of delivering a session with a gloomy name Seven Deadly Sins of CRM Development. That’s right, doom and gloom, and Spießrutenlaufen, all over again. I will come back to the topic in the future but for now I want to talk about one of the demos we run during the presentation.

I opted for an easy way out – walk through The Curse of The Browse Button and be done with illustrating the point. I’m glad I asked though how many people actually use NuGet in their development, because the entire room shot up. Oops, here goes my demo. To save the face I probed the subject of how many people use chocolatey and, lucky me, only one hand showed up.

What is it, you may ask? In a nutshell, it’s a silent command line package installer for Windows, based on NuGet. Why bother using command line to install something that you can do by pointing and clicking? Because it works and it makes you productive.

Want to install .net 4.5.2 developer pack to be able to use latest CRM SDK assemblies? Search for the pack on the internets, download, extract, run the installer, answer wizards questions and watch the paint dry. Or:

  • Open elevated command or Powershell prompt
  • Type clist netfx-4.5.2-devpack, press Enter

Not so long ago I had to reset my Surface and all my beloved programs were removed leaving me with the barebone Windows. Since every now and then I get the list of the installed packages by running clist -localonly, and save the result to to OneDrive, restoring all of them in one go was a breeze.

If you want something more versatile than that to manage repeatable environment builds, have a look at the Boxstarter.

Demo saved, productivity is up, mouse is taking a break.