CRM 2013 – How add a status reason using the CRM SDK

I recently had a tricky problem created by myself when I deleted a Status reason without fully engaging my brain.   Read more about it in the link below

CRM 2013 – Understanding Status and Status Reason – think before deleting them

Adding a Status Reason

If you try to add a status reason in CRM you will quickly find you can specify the label but not the value

optionSets

I’m not sure why it works like this but it was very frustrating when I was trying to add a Status Reason and wanted to specify the value.

Unsupported Database change

Someone did murmer the words

“Direct Database update”

My advice to CRM developers is to not even think about unsupported changes because Microsoft will un-support your CRM if they find out

Why you shouldn’t put unsupported customizations in Microsoft Dynamics CRM

Don’t do unsupported CRM customizations, 99.9 percent of the time there is another way and for the 0.1 percent of the time you should go back and tell the customer you can’t do it because it’s unsupported– Hosk Quotes

Start with the CRM SDK

When using the CRM SDK it usually a journey of discovery, reading one page, which leads you to another page, slowly pick up the clues, information and examples until you have enough information to tackle the problem.

I say it so often it’s made it to my Hosk Wisdom quotes page

Always start with the CRM SDK, you will find the answer to your current problem and solutions to your future CRM problems  – Hosk

 

I knew status reasons fields are option sets and option sets store information

Value (int number)

Text (description)

The description is held as Metadata.  If you want to learn more about metadata read my blog post Understanding CRM Metadata.

Using the Metadata services it’s possible to add, update and retrieve Metadata fields.

The Work with attribute metadata page had a section called Insert a new status value.  This was good but in the example it didn’t specify the value.  I needed to specify the value because I was trying to add back a previously deleted status reason, read this blog post to find out why I was trying to do that.

When using the CRM SDK you often need to earn the answer, this means you need to read, analyse and understand how parts of the CRM SDK work.   This is the sample code

InsertStatus

It’s adding a Statecode (e.g. Active/In Active) but I want the StatusCode.

I look at the msdn page for InsertStatusValueRequest Class, this links to the same code as above but on the left you can see more pages you can look at.

InsertStatus 1

It’s often worth looking at the related documentation for classes in CRM. In this case I look at the InsertStatusValueRequestProperties

InsertStatus 2

There it is Value, yippeee, that’s what I want to set. I can see from the documentation it’s optional, which would explain why it wasn’t included in the sample code.  Most people are not worried what the value of a new status reason is.

I have the theory, now it’s time to put it into practice.

CODE

Here is the code I used to create a status reason and specify the value of the status reason to be 100000001.  Quite how the number got created like that puzzled me, unless a previous developer used the same code!

 // Use InsertStatusValueRequest message to insert a new status 
 // in an existing status attribute. 
 // Create the request.
 InsertStatusValueRequest insertStatusValueRequest =
 new InsertStatusValueRequest
 {
 AttributeLogicalName = "statuscode",
 EntityLogicalName = Incident.EntityLogicalName,
 Label = new Label("Correspondence Withdrawn", 1033),
 StateCode = 1,
 Value = 100000001
 };

 // Execute the request and store newly inserted value 
 // for cleanup, used later part of this sample. 
 int _insertedStatusValue = ((InsertStatusValueResponse)this.crmService.Execute(
 insertStatusValueRequest)).NewOptionValue;

One last point of interest was I hard-coded the UK locale, Microsoft example just specified a variable but didn’t show where it was assigned.  I looked up the value on this page – Locale ID’s assigned by Microsoft.

As this was a one-off, I was worried about the hard coding

Advertisement

What’s new in CRM 2015 SP1 for developers, customizers and admins

When there is a new release for CRM the SDK publishes a what’s new.  I recommend CRM developers read this, I have written a blog post about the subject

Why developers should read the CRM SDK what’s new

Here is my quick review of the last one

CRM 2015 – Hosk takes a peak at the CRM 2015 SDK

CRM 2015 and this update and with this particular update Microsoft seem to be adding lots of useful functionality for developers rather than front end functionality.  This is one of the major development releases for Microsoft Dynamics CRM since I have been a CRM developer.

The consolidation of functionality CRM 2015 is a good idea and will be beneficial to CRM suppliers and CRM developers.

The documentation for CRM 2015 SP1 is excellent.  There are a lot of developer and subtitle updates and added features, all of which are well documentation so thumbs up Microsoft.

My goal of this blog is to summerize the information of the CRM 2015 SP1 update

  • Give useful links
  • condense information
  • Hosk thoughts on the functionality

Useful links for Administrator’s and Customizers

Below is a collection of links about CRM 2015 SP1 in general and not focusing on the Developer enhancements.

CRM Online 2015 Update 1: official pre-release content is here!

This what’s (new is good for non Developer related highlights)

CRM 2015 Update 1 videos

What’s new for administrators and customizers in Microsoft Dynamics CRM 2015 and CRM Online

What’s new for developers

There is so many juicy news bits of functionality, I recommend you read the what’s new for Developers in it’s full glory.

What’s new for Microsoft Dynamics CRM Online 2015 Update 1

Upgrade considerations

This technet article was interesting

Before you upgrade: issues and consideration

IE 10 and 11 are only supported in CRM 2015

Those upgrading from CRM 2013, in CRM 2013 CRM had base and extensionBase tables but these are merged.  There is a section called

Base and ExtensionBase table merge cannot be deferred (if you didn’t know Microsoft got rid of the ExtensionBase table and now only have one table for each entity)

To find out the amount of table data that will be merged during upgrade, see Determine how much ExtensionBase table data will need to merge.

This is a great example why you should never write customizations (web services, reports or plugins,  I’m sure there will be some developers who have written reports based on the extension and base table which will all break when upgrading to CRM 2015.

The page states in place upgrades are not supported for these products (which is worth keeping in mind)

  • Microsoft Dynamics CRM 2013 Reporting Extensions (on-premises only)
  • Microsoft Dynamics CRM 2013 Email Router
  • Microsoft Dynamics CRM List Component for SharePoint Server

Updating CRM 2015 online

I will admit to not knowing if this was changed or if I have just read about it.

Manage Microsoft Dynamics CRM Online updates

The technet article mentions the functionality of delaying and choosing a time to schedule your CRM update.  The bottom line is you have to approve the update before it is applied.

The article mentions you can choose not to deploy an update.  I have wondering what happened to CRM online instances which automatically updated and the chaos in panic testing this would bring about with a set deadline in place.  Some CRM organisation have lots of customizations need a lot of testing.  so it can be some time before a company wants to apply a CRM update

What’s new for developers

My initial plan was to review a lot of the changes in a series of blogs but I noticed today that CRM MVP Daniel Cai has already done it.  He has done a great job, awesome work.  So I changed my plan to build on his good work rather than duplicate it.

New SDK Capabilities – CRM Online 2015 Update 1 release

Daniel has written 9individual blog posts which go into detail about the new functionality and with the all important screen shots.  Daniel has done such a great job there isn’t any point in me doing it again.  I have linked to his blogs and given a quick summary of the functionality.

I recommend all CRM developers read Daniels blog links to get a good idea of the new functionality and don’t just read my quick summary

Fantastic functionality which allows you to create alternative Keys.  Alternative key doesn’t make it initially obvious what the functionality does (to me anyway).  It allows you to create a new unique identifier for a record made up of a combination of columns (e.g. think composite key maybe foreign key).

The columns used to create the alternate key must be either String/Integer/Decimal.

CRM will index these in the background and you can monitor the creation –  Monitor index creation for alternate keys

The result of this means it’s easier to create/update records in CRM and in applications integrating with CRM.

When I read about Upsert I thought it was a joke, Upsert.  The functionality although sounds funny is a great idea.  The premise is it’s an Update and insert.

When using an upsert the functionality checks to see if the record exists, if it does it updates the record. If the record doesn’t exist it creates the record.

Simple but very effective because for integrating applications it avoids the round trip of checking to see if records exist and then choose to create or update.

Another pragmatic piece of code.  This improved functionality allows standard calls to do things like assign values, setting state, before the update you need to use special messages.

This post will give you more details

Perform specialized operations using Update

CRM Online instances can turn on plugin tracing logging, which creates a trace file you can look at.  Very useful considering you couldn’t view any logs before (because you can’t get onto the server).  This would allow you to view the values used in your plugins.

Entity change tracking allows you to detect if the data you retrieve has changed.  This would enable you to do a retrieve and only return the data which has changed from your initial retrieve.

This page from Microsoft will give you more detail and the title explains it’s intended use

Use change tracking to synchronize data with external systems

More CRM integration changes.  This functionality allows you to batch a bunch of actions into one transaction.  You can roll the transaction back if any of them error.  Microsoft Calls this Multiple message execution

Very useful for code integrating with CRM.  Read more on the CRM SDK – Execute messages in a single database transaction

This is a biggie.  This functionality tells you if the data you are going to update has been changed in between you retrieving and updating the information.

It uses a RowVersion value to see if the value being updated is the latest and if so it will throw an error, which means you can retrieve the latest and then update.

CRM SDK link – Reduce potential data loss using optimistic concurrency.

You can now check what version the CRM server is running on.  This offers you the ability to create branches in the code to use different functionality.  This could be useful in commercial solutions or maybe creating solutions to work across different CRM versions.

Try the Web API preview

This is interesting, they are offering you a preview but you shouldn’t use it in production environment (It’s not finished yet I guess).  You might be thinking, why do I care about a preview.   The new web api uses OData v4, OAuth 2, and JSON

It’s this line which intrigues me

The preview release allows you to give feedback and get an understanding of what is coming in a future release. The Web API preview shouldn’t be used on production environments and no support is provided. For more information on the next endpoint,

Learn more here – Web API Preview.

Improved Sub Grid Javascript

You can change the selected view for the Javascript and get the entity references easier

Non developer improvements

A quick summary of what’s in here

What’s new

Improved CRM navigation

quick video

The change now shows all the potential links when you click on an area e.g. sales.

So where before you had to scroll along to see the options, now they are all displayed

The recently viewed is a global tool (e.g. available in many parts of CRM) allows you to view recently viewed records and pin items

Themes

You can change the colours and add a logo.  This is like changing your theme in windows.  It will change all the colours of the bar

Watch a short video (2:45) about themes

Theming post from powerobjects

Onenote integration

Track emails with folders

This is a good productivity improvement.  It allows you to track emails in CRM by copying them to a folder.

folder level tracking

Export to Excel

It shows how much CRM developers use excel to export and import data by the fact I was quite excited by this enhancement.

This has been completely rewritten and you can now import/export 100000 instead of the previous limit of 10000.  This is excellent but strikes me as one of those changes which should have be done a while ago but lets not complain because its in now

New export to excel functionality

CRM Gui Customization changes (non code)

This page is very useful

What’s new for administrators and customizers in Microsoft Dynamics CRM 2015 and CRM Online

This page above includes all the changes and updates for non code customizations, which I sometimes call GUI customizations.  It does also mention some config settings

Older than X

this was limited to months but now you can specify minutes, hours, day, week, years.

Older than 5 minutes

Older than 1 year

Older than 2 weeks

Daniel Cai has written a blog post on this if you want to learn more New Query Operators

Date only field

CRM 2015 SP1 can have Date only fields and Time zone indepdent.  This is different from creating Date and time fields but only displaying the date.  Why did it take so long to add this?

Clear field with Business rules

Microsoft keep adding improvements to business rules which is good and need.  The next improvement allows you to clear fields.

Auto Creating CRM records not just for cases

Previous versions of CRM you could create Cases using emails and other social posts.  The documentation says other social messages but for most people this is emails and perhaps phone activities.

This functionality has been extended to sales and marketing.  So emails and other activities can create System or custom entities.

Rollup fields can use AVG

Rollup field can use AVG in calcluations

Mobile phone and tablet apps have been improved and I will expect this to be mentioned in every new release for the forthcoming future.

Final thoughts

A theme of this update is synchronizing CRM with external systems (applications, web services, 3rd party software).  Microsoft have made it much easier and quicker to synchronise data between CRM and other systems whilst adding functionality for checking data (e.g. to avoid overwriting already changed data)

Microsoft shows you how the changes work together

Synchronize CRM data with external systems

These two images from the page above succinctly show you the potential improvements

Before CRM 2015 SP1

After

I can understand these improvements are very useful but what puzzles me slightly is the sudden motivation to add this functionality into CRM 2015.   If anyone knows the reason or has an idea please add a comment.

Most of the CRM projects I have worked on have been extremely customized and used Microsoft Dynamics CRM for XRM developer.  CRM was the framework to build a solution for the customer.  The new updates in CRM 2015 SP1 take this a step further by making it easier to not only create the main solution but create applications to integrate with the CRM solution.

This fits in with Microsoft’s recent tactics of acquiring applications/software and integrating them with Microsoft Dynamics CRM (Parature, Unified Service Desk, MDM, Social engagement).