Category Archives: Programming

Service Level Agreements on Case Entity in MS CRM Dynamics 2016

The Case entity has the built in capability to use Service Level  Agreements (SLAs). Often SLAs are in place to contract a service delivery time for a customer, however we will be using it for a slightly different purpose in this example.

This tutorial assumes you have basic knowledge of the Case entity, sending Emails, and Workflows within Microsoft Dynamics CRM.

This step-by-step tutorial illustrates the following situation:

  • Upon receiving a project request, a Case is created and information is entered
  • Case is then then assigned to a user
  • If a Case has not been assigned for 5 days, send an email to a manager
  • The SLA will succeed when Case is assigned
  • The SLA will fail and send an email if Case has not been assigned within 5 Business Days

 

The first step is to ensure proper Business Hours are set up for the Organization

  1. Navigate to the Service Management area: Settings > Business > Service Management

  1. Navigate to Customer Service Schedule and choose “New”: Service Terms > Customer Service Schedule > New

    3. Name your new Customer Service Schedule and add a Description.
    4. Choose Work Hours and Days which correspond  to the company’s working hours and click Save and Close. For the sake of this example, I have chosen Monday – Friday, 6am to 5pm. If we do not add a Customer Service Schedule, the SLA would count Saturday and Sunday towards the countdown time, but we want to restrict it to only count work days.


The next step is to create and configure an SLA for a form

  1. Navigate to the main Case form in your Solution to ensure the SLA KPI fields you require are on the form. I have kept the default Applicable SLA(STANDARD) Section which includes “First Response By” and “Resolve By” under the Summary tab. Let’s choose a field to be our flag: we will change it when the record is assigned. Add “First Response SLA Status” to the form. Its default value is “In Progress”, and we can change it to “Succeeded” when the record is assigned.

  1. Create the SLA: You can create a new SLA through the Solution, or by navigating to Settings > Service Management > Service Level Agreements.

  1. Name your SLA and choose the entity – we are choosing the default Case entity, but as of CRM 2016, other entities can have SLAs enabled for them as well.

  1. Enter the details for the SLA such as Business Hours, the Type and Description. I chose Standard because we do not need the ability to Pause and Resume at this time, which an Enhanced SLA would allow us to do.  As well, this SLA will be “Applicable From” creation of the Case.
  2. Under SLA Details, click the ‘+’ to create a new SLA Item where we will configure our workflow logic.

  1. The Related Case Field is where you choose a Date/Time field which will show the “due date” or Failure date/time on the form. You can choose any Date/Time field, but I stuck with the default: First Response By.
  2. The “Applicable When” section defines when the SLA should activate. As we want it to be active on all cases, no matter the priority, we will leave it blank.

  1. The “Success Criteria” section defines what logic must be met for the SLA to succeed and stop counting down. In our case, we have added the extra field “First Response SLA Status” to the form. Let’s stop the SLA when the value of that field on the Case form equals Succeeded.

  1. To finish up our SLA Item, we need to set up a Warning or Failure action. In our case, we want to send an email to a manager if the case has not been assigned within 5 days. In other words, if “First Response SLA Status” is anything other than Succeeded, the SLA will Fail after 5 days and send the email.

Set “Failure after” to 5 days (the max in the drop down ends at 3 days, but you can manually edit this field) and Add Step “Send Email” under Failure Actions. Set the properties of your email to send whatever message you choose, and send to whomever makes the most sense. No Warning is needed for this example, but you could choose to have an action occur before the Failure date to warn the user.

The last step is to create a Workflow to set our flag when a Case is assigned

  1. Our SLA will succeed when the field “First Response SLA Status” equals “Succeeded”, so let’s create a workflow that sets the field when the Case is assigned.
  2. Navigate to Processes within the solution and choose “New”.  We’re going to create a Workflow(Category) for the Case(Entity). If you want the field to update automatically (Real-Time Workflow) and stop the SLA within seconds, uncheck the “Run this workflow in the background” box. I have left it checked as an Asynchronous Workflow will work fine for this example.

  1. We want this workflow to change the value of the field when the Case is assigned. In order to set the trigger, we can choose to “Start when:” Record is assigned.

  1. Now we can change the value on the form. Click “Add Step” and choose to “Update Record”. After selecting Case, click Set Properties to set the value.

  1. Let’s change the status to “Succeeded”.  Save and close.

  1. Don’t forget to publish your changes! As a last step, let’s change the “First Response SLA Status” to read-only on the Case form, so no one can manually change it to succeeded.

Go forth and test!

  1. Test out the SLA to make sure it stops and does not send an email after the record is assigned
  2. Test to ensure that an email is in fact sent when the SLA has failed
  3. Optional Steps:
    • Consider renaming the First Response SLA Status field to something more specific to the SLA, for example: “Assigned Status”
    • Another alternative is to create a new field as your flag, perhaps a Two-Option Set (Yes/No) called “Is Assigned?”

Make a Custom Button Web Resource (HTML/JavaScript) in Microsoft Dynamics CRM

Sometimes you just need a button. Adding a custom HTML button to an entity form in CRM has a ton of onClick() possibilities:

  • Hide a section or tab on the form
  • Trigger a workflow
  • Allow a user to submit information
  • Validate data entered by a user
  • Lock, unlock or update fields
  • Display a celebratory fireworks animation and play a .midi file

Okay you might not want to do that last one, but the possibilities are endless! This post will show you how to create a simple button in HTML and add some JavaScript to perform a function.

At work I had the task to create a button on the main Email form that would trigger a workflow. Our client wants to be able to review a few draft emails, then press the button to iterate through all draft emails and send them.

Create the Button Web Resource

Navigate to your solution and create a HTML New Web Resource.

 

 

Open up the Text Editor (or something like Notepad++) and create your button by adding HTML to the Source tab. You can preview your button on the Rich Text tab. It can be as simple or as detailed as you want it to be, here’s some barebones code. After you save your web resource, Dynamics automatically adds a few tags.

 

Add a Script to the HTML

Looks great! Now let’s make something happen when you click it. Let’s add some <script> tags with a JavaScript that changes a field’s value when a user clicks the button. We’ll call the function “changeFieldValue_onClick” and add an “onclick” event to the button.

A few notes about the code above:

  • Adding “debugger;” to the JavaScript allows you to step through and test your button after placing it on the form. An example of this is shown below.
  • var sendEmail holds the Attribute “esdc_sendemailtrigger” which is a Two Option Set. We then check if the value is “No”. If it’s “No” (false), set to “Yes” (true).
  • My custom workflow is triggered on the field change of “esdc_sendemailtrigger”: if it’s set to “Yes” the process is run and then it sets the value back to “No”.
  • I added the .setSubmitMode(“always”) to ensure the value of the field is changed immediately on the click of the button.
  • Lastly, don’t forget to call your new function “changeFieldValue_onClick” to your HTML button’s onclick event.

     

 

 

Publish All Customizations (<– very important step!). Okay your button is ready for action! Go ahead and pop that on any form or entity of your choosing. The field I want to change is on the Email entity’s Main Form, so I’ll put it there. Navigate to the Insert tab on the Form Editor, choose a section and press Web Resource.

 

Find your new button in the Lookup, give it a Name and optional Label. Save and publish your customizations and now you can take a look at your form and test the button. Press F12 before pressing your button to use the debugger and step through your code.

Fin!

 

Creating an Email with Template in MS Dynamics CRM 2016

InstantiateTemplateResponse message in Dynamics CRM 2016

I had a heck of a time with the Microsoft documentation on this issue, so thought I would throw up a quick blog post to help anyone else with this task.

My work requirement:

Generate an email for all Active Organizations in Draft status. The email must have Excel files from Notes attached and use an existing Email Template.

There were many components to this problem that required a custom workflow rather than OOB functionality. For example: there will be more than 5000 Organizations queried, which meant needing a Paging Cookie as the data set was very large. I was also running another custom assembly that generated the Excel files for each Org and attached them to the Notes section. MS CRM OOB (Out of the box) provides no way to dynamically attach Note attachments to an email, so I would need to create the email programmatically and dynamically attach the documents.

I developed most of the solution over a week, but the past 4 days have been a struggle. I’m working a student co-op position: truly learning as I go with Google being my main mentor and resource. The main issue where the Microsoft docs let me down was instantiating the Email Template.

My requirement was to generate the email in Draft status, preventing it from sending immediately, so I could not use the SendEmailFromTemplateRequest message which creates an email from a template and sends all in one step. Instead, I would need to use the InstantiateTemplateRequest message . The official documentation does not provide the hint that the email is not created, in fact it is only the email “message” which you’ll need to parse out of the Email Entity created, add to your Email and Create() with a CRM service call.

 

The InstantiateTemplateResponse class holds an EntityCollection (Email) with the Attributes of “subject” and “document” retrieved from the Email Template. In my code below, I assign these attributes to the Email’s Subject  and Description, using a mix of Late and Early Bound entities.

I couldn’t find any code examples of this online, so hope it helps someone!

How I made my first game: Part 3

Ludum Dare #38 Post Mortem – Part 3

Here’s a link to Part One!
And click here for Part Two!

Part 3

Goal – tending

Did I reach my goals? Let’s revisit and check them off:

  • Have an awesome fun experience! ✅
  • Learn something new ✅
  • Gain some estimation skills ✅
  • Know when to pivot (or push though) if something isn’t working ✅
  • Finally start and finish a project O: ✅

So so pumped to have completed this challenge with a finished game! It is polished? Heck no! It’s possibly not even fun to play – but it sure was fun to make, and selfishly this Ludum Dare was all for me bb.

 

Programmer’s Delight

Let’s take a look at a few nitty gritty details – the game may not be much from the outside but it has some pretty cool elements on the inside. All credit for this goes to SlasherXGAMES and his tutorial, but I will do my best to explain some concepts:

  1. 2-dimensional array – Implementing the 2-d array was a great way of randomly generating the flea pairs by ensuring there would never be a lone flea without a mate. The array keeps track of the flea index, flea sprite and flea id of the first click and the second click. A comparison is made to compare the two and decide whether a match is found (yay!) or not (boo!).
  2. Advanced matching – so I should’ve gone the easy route and just made a colour or shape matching game – but it just didn’t feel right in the flea-world. I wanted to add a little pizazz, so I referenced a more difficult matching game tutorial. The idea is to use one sprite with multiple frames, so the player is matching a similar (but different!) flea rather than the exact same one.
  3. No Drag and Drop here! – I am very excited to have used a ‘controller’ in each room to populate the visual elements. A nested for-loop is used to populate each flea-type, using counter variables to ensure there is always a mate for each flea! No flea left behind.
  4. Animation? When the user makes a correct or incorrect match, the dog reacts and the fleas make a sound! Hey, it was my first game, cut me some slack 😉

Now that all is said and done, here’s a list of the software & tools I used:

  • GameMaker: Studio Pro
  • Trello
  • GIMP
  • Audacity
  • Notebook & pencils
  • Slack
  • Windows Calculator since apparently I suck at counting fleas

                 

What did I learn?

I definitely should have paused the tutorial to test and run the game early and often! D’oh!

GML is pretty user friendly! The documentation is clear and concise and I enjoyed searching through the docs before turning to Google. The more programming languages I run into, the more I realize how similar and universal some core principles are. Variations in syntax are a learning curve for sure, but I’m definitely gaining coding confidence!

What if I kept working on it?

Well, I am probably not going to take this game any further, but my original brainstorm gives me an idea of what the grand vision of the game could be. I imagined it in old flash game meets slick mobile app style.


The game begins with a little animation zooming in on the dog’s weird face (a-la-Ren&Stimpy) and then zooming in even closer to see the fleas hanging out in their natural habitat. Ideally the fleas are animated for the whole game, wriggling around and dancing to the background music. Each level would increase in speed and difficulty and the animal would change (dog -> cat -> giraffe -> unicorn -> etc).

A timer function and score multiplier would increase urgency and reward you for matching fleas fast. Of course there would also be a high score table which may add replay value? Anyways! That’s my game in a utopic timeline.

Next Ludum Dare

I can’t wait to try again and push myself way harder. Now that I know I can complete a small game in a short amount of time, I want to challenge myself:

  • Start with the same game plan, but take the graphics through at least one more iteration to clean it up visually
  • Have a better understanding of the core basics of game development
  • Work with a team!
  • By next time I hope to have experimented with GML and learned the strengths\ limits of GameMaker: Studio
  • Communicate and network with others working on their own Ludum Dare projects

 

UPDATE: The Results are In!

Well folks, thanks for reading my 3-part post mortem! I really enjoyed by first Ludum Dare experience and look forward to playing and rating your Ludum Dare games! Comment with a link to a game you’ve made and I will give it a whirl.

Of course, click here to play Match the Fleas!

Yay! In the top 8th percentile for humour 😀 I got tons of amazing feedback from this very friendly community. I can’t wait to apply it to the next Jam at the end of July.

How I made my first game: Part Deux

Ludum Dare #38 Post Mortem – Part Two

Click here to read Part One!

Ludum Dare is split into two parts: The Jam and the Compo. The Jam lasts 72 hours and is fairly open and flexible. The Compo is a bit more challenging, only 48 hours and you must share your source code at the end of the competition.

I had 2 reasons for choosing an easy-to-create game:

  1. I had an optometrist appointment Saturday morning so although I got up at 8am to eat a good breakfast, I dashed out to learn how to jab contacts into my eyeballs and didn’t get home until noon.
  2. I had a commitment after work on Monday which meant I would have to submit on Sunday (48 hours), although I would submit for the Jam because my source code would mostly come from the aid of tutorials!
A little PDL never hurt anyone

I’m not really into cowboys, so I did a bit of planning before I started coding. Admittedly my game development knowledge is lacking, so I attacked it like any other coding problem and detailed what I thought the game loop might look like.

First things first – I hate DnD

Dungeons & Dragons is great, Drag is great, Death Drops are great – Drag n Drop… mmm not so great. This is something I avoid when making mobile apps in Android Studio. The idea of drag-and-drop is to add ease and simplicity to a process, however I find the underlying code can be messy and often it’s more frustrating and encumbering than quick and easy. I felt confident enough in my junior programming skills to avoid the DnD feature of GameMaker as much as possible. Learning GML (Game Maker Language) would be a great way to cross “Learning something new” off my goal list.


After searching for a few “matching game” tutorials, I stumbled across this one that met my needs perfectly. I coded along while watching the video, altering things as I went and making tons of comments. I did not pause the video and test the code… this was my first mistake – got all the way to the end of the video and pressed “Run”… it didn’t run? 🚷

I get knocked down…

Well I was stuck for quite a while! This was quite the dilemma, I had been on a roll but now? Stuck! Of course it was bound to happen, but I couldn’t help but feel a bit hopeless with time running out.

I considered the pivot! Should I scrap everything before I make any art and use Twine to create a story based game? Should I start from scratch with the tutorial again? I needed a break.

But I get up again!

I hopped on the bus to my friend’s place for moral support & discovered the GameMaker debugger! Bless. 🙏

My while loop was the culprit. Control flow wasn’t flowin’. Also, my brain does not compute x & y coordinates very well. In fact my wild guesses as to where to put things and how many to put where were close but wow I really should have taken a moment to draw a grid and figure it out. Lesson learned!

Speaking of lessons learned – I learned a LOT during this process! For example, I got the chance to implement a 2-dimensional array, which previously I had only experienced in a final exam: coding with pencil and paper. Really fun to see it work its magic. I’ll dive into this more in the next post.

It’s alive!!!


With the game running I was back in action and stayed in a groove until around 9pm. In that time I whipped up some sprites and a nifty “animated” background in GIMP. I tweaked the logic so the game was definitely playable as-is, which meant I could spend the rest of the time with assets. I stuck with my first iteration of in-game art: aka WYSIWG or whatever happens, happens art. 😉

I took the rest of the night off for a hearty meal and video games, of course. Slept in the next morning, and got back to work around 10 on Sunday. Throughout the afternoon I alternated from designing the start and winning screen, to recording audio sound effects with Audacity.

Match the Fleas Ludum Dare

👏 The game was finished & submitted, with time to spare! 🎉
 

Tune in to the third post of this 3-Part retrospective, where I share the finished game and reflect on what went wrong, what went right and what the future holds!

How I made my first game in under 48 hours!

Ludum Dare #38 Post Mortem – Part One

Check out Part Two here!

I did it! I made my first game and participated in my first Ludum Dare all in one weekend.

Ludum what?

If you’re not familiar with Ludum Dare, it is a themed game jam where people all over the world create a game from scratch in 48 (or 72) hours. A new jam/compo happens every 4 months, and I have a few friends who take part almost every time. I’ve wanted to try my hand at it since I started learning to program. Thankfully the stars aligned and I was finally able to participate in Ludum Dare #38!

 

 

Why am I doing this?

My main goal was simply to complete a game by the deadline. I imagined this would require some planning, so I started preparing for the jam on Friday after work, before the theme would be announced at 9pm.  Oh – also I was hoping to:

  • Have an awesome fun experience!
  • Learn something new
  • Gain some estimation skills
  • Know when to pivot (or push though) if something isn’t working
  • Finally start and finish a project O:
How am I going to actually finish this by Sunday night?

I figured I would set some boundaries and basically remind myself not to let my head get too far in the clouds. It’s great to have fun and creative ideas for a game, but I have never really made a game before so I jotted down a few notes:

  • KISS (Keep it Simple, Stupid)
  • Know your limits
  • Use your toolbox (put my programming basics into practice!)

 

What is going to go wrong at the worst moment?

I was definitely excited, but also feeling nervous, so I thought of some challenges I may come up against:

  • Not being able to finish in time by:
    • Getting stuck on a bug
    • Being too unfamiliar with the software
    • Scope too big

 

Anxiously awaiting the Theme announcement…

Lastly, while I counted down the minutes to 9pm, I channeled my inner project manager to (hopefully) set myself up for success:

I made a list of simple types of games that would be easy for a beginner. Some that came to mind were: Pong, Space Invaders, point-and-click, avoid/collect and perhaps a soundboard. Before I knew it, the clock struck 21:00!

 

 

Ludum Dare #38 Theme Announced: A Small World

I actually did vote +1 for this theme because I knew I could work with “A Small World” with any of the beginner game tutorials I had researched. However, all of the themes in the last round of voting seemed definitely doable.

With my initial brainstorm time-box being a humble half hour, I started sketching and making notes immediately. To be honest, I love a good creative brainstorm where the only rule is: nothing is off limits. I followed advice from a Ludum Dare alumni: “Write down the first thing that comes to mind – it’s likely the idea everyone else will be doing, so keep thinking!” By 9:20 I had come up with a few ideas that seemed fun!

Initial Ideas

 

    1. A Space Invaders-style (ish) game!

      An animal-like alien stands atop a planet. He holds a leaf over his head and protects the small world from acid rain droplets. Inspired by old Neopets flash games where you basically just move side-to-side catching items as they fall to the ground.

 

  • A twist on Pong!

    The ball is a large planet that shrinks and speeds up every time it bounces off a paddle. 2 paddles, one AI player. The large planet becomes (wait for it…) a literal small world. 😀

 

 

  • Asteroid-style!

    The player controls a small planet-turned-spaceship, flying through space to gather needed resources and avoiding black holes. Subconsciously inspired by those episodes of Invader Zim where Mars is a spaceship (Battle of the Planets).

 

 

  • A matching game!

    An extreme close-up on a dog’s fur reveals a small world of fleas. They love their environment and thrive on finding a mate to reproduce. The dog doesn’t seem to mind.

 

Flea Game

I was feeling really good about the matching game, it seemed fun and hopefully simple enough to complete within the 48 hours. I used the drag-and-drop system in GameMaker: Studio Pro to make a quick “mock up” of how sprites and objects might work together, then went to bed to prepare for an early morning!

Head on over to Part Two, where the real coding begins and I almost give up before I ever really got started!