Wednesday, October 13, 2010

World First Exclusive: Dynamics CRM 2011 as a Games Platform

You heard it here first, XNA is dead, long live Dynamics CRM 2011. Dynamics CRM 2011 is so powerful you can design games on it. Admittedly the game is hangman in this case but it is possible using the new dialogs feature. As a further testament, this took me about an hour to put together starting from a very low knowledge base of dialogs.

The Structure

First of all I created a new solution in case the boss feels a hangman game is not appropriate for our demo server

image

This way it is really easy for me to remove my work by simply deleting the solution.

Within Hangman there is a new entity called Word and two Dialogs (Hangman Dialog and Hangman!)

The Word Entity

image

The bits of interest are in the Word section (by the way to add a new section, go to insert and look for the column formatting).

Letter 1-6 defines the word of interest, Guess 1-6 stores the state of guessing and Guesses stores the number of incorrect guesses.

The Hangman Dialog

I’ve got multiple screenshots because of the limited scrolling capability within the dialog configuration form.

image

So this Dialog is On-Demand and a Child Process. This works the same way as Workflows. This means I can manually call the Dialog and have it loop.

I did not use the Input Arguments and Variables. To be honest I’m not sure what they do.

First there are a couple of conditional statements. The first sets the Guesses field to zero. The next checks if there have been 10 incorrect guesses and if so it spawns the Hangman! Dialog whose only function is to display the word ‘Hangman!’ and finish the Dialog.

To get a popup, we now create a ‘Page’ step.

image

We prompt for a letter and in the prompt add dynamic information such as the letters correctly guessed so far and the number of Incorrect Guesses. This was really hard to set up because the dynamic fields, just like in version 4 do not always get placed at the cursor. To make matters worse, if I tried to cut and paste a dynamic field it worked but on exiting, the whole text got converted to broken html and I had to start again. My tip for beta: add the dynamic fields first in the order you want them and then type the text around them.

image

After the page prompt a set of if statements checks whether the input value matches any of the letter values and if it does it populates the corresponding Guess field. You can access the user’s input for the conditional pretty much the same way as you access workflow attributes in workflows now i.e. through the form assistant and dropping down the referencing entity to, in this case, Dialog.

image

If the input matches none of the letters, the Guesses field is incremented by one (you can do this in workflows in version 4 but it is a relatively unknown feature. Click on the field and again play with the form assistant. You’ll need to use the default field and set it to one to get the increment working.

Finally I call the Dialog to loop it.

CRM Hangman in Action

First we create a word.

image

We only need to fill in the letter values. The name is not used but is the default attribute for the entity. If desired, the compulsory status could be removed and the field taken off the form.

You then save the record and click the Start Dialog button on the ribbon, selecting the Hangman Dialog

image

You then enter the letter in the text field in the blue area and hit next. The Dialog loops until you have made 10 guesses or until you give up/guess all the letters.

image

Things I Learned

  • You can’t spawn a Dialog from an event, like Workflows. For example, it would have been great to kick off the Dialog on the creation of the Word record. I could not figure out how to do this
  • You cannot spawn a Dialog from a Workflow but you can start a Workflow from a Dialog. I’m guessing this has to do with the asynchronous nature of Workflows
  • Given enough time it should be possible to create an Infocom-style adventure game (http://en.wikipedia.org/wiki/Infocom). I’ll leave that as an exercise for the reader. You’re in a room with exits to the North, South and West…