Tag Archives: CRM 2013

Fix Incorrectly Created Status Reasons in Dynamics CRM

The Status Reason field in Dynamics CRM is a special field which allows you to provide reasons for the status of a particular record. For example, an Article can have a Status of “Active” and a Status Reason of “Awaiting Review”, “Approved”, “Published” etc. Likewise, an Article can have a Status of “Inactive” and a Status Reason of “Expired” or “Deleted”. But what happens if you configure your Status Reasons incorrectly?

I had recently made a mistake while configuring the Status Reason field such that a user could set an Article to Active – Deleted, which was not the desired functionality. The “Deleted” status reason should instead be linked to the “Inactive” state.

clip_image001

The CRM implementation also enforced strict rules so that the “Deleted” status reason must have an ordinal value of 213,940,003. Let’s see what happens when I try to simply re-create the “Deleted” status reason against the “Inactive” state.

If I try to delete and re-create the “Deleted” status reason, the CRM platform automatically assigns it the next available ordinal value of 213,940,006 and it appears that I cannot change this value.

clip_image002

Thankfully there is a way to change this value without any nasty database hacks.

Firstly, remove the “Deleted” status reason, save your changes and publish customizations. Next, add the “Deleted” status reason to the list of “Inactive” status’ as we previously attempted.

clip_image004

On the Add List Value screen, press F12 to launch Internet Explorer Developer tools.

clip_image002[1]

Make sure the HTML tab is selected and then select the cursor icon.

clip_image005

Back on the Add List Value screen, hover over the Value textbox so it appears with a blue outline and then click the mouse.

clip_image006

Back on the Internet Explorer Developer Tools screen, on the right-hand pane, select Attributes and then select the disabled attribute. Press the delete button to remove this attribute.

clip_image008

The Value field will now be editable. Change the value from 213,940,006 to 213,940,003 and then click on OK.

clip_image009

Save the changes to the Status Reason field and publish customisations. The “Deleted” status reason will now be available to select when making records inactive.

CRM 2013 – Asynchronous Solution Import

The new Dynamics CRM 2013 SDK includes a new method to execute service requests asynchronously which currently only works for asynchronous solution imports at the time of this writing. The main benefit of an asynchronous solution import is that there is less of an effect on users who are interacting with the system when the solution is being imported. Previously, users would get locked out and would experience a SQL Server error during import.

The following code snippet can be used to execute an asynchronous solution import in CRM 2013.

var connection = new CrmConnection("Crm");

var service = new OrganizationService(connection);

var context = new CrmOrganizationServiceContext(connection);

IOrganizationService sdk = (IOrganizationService)context;

ExecuteAsyncRequest request = new ExecuteAsyncRequest

{

Request = new ImportSolutionRequest

{

CustomizationFile = File.ReadAllBytes(pathToSolutionFile),

PublishWorkflows = true,

}

};

ExecuteAsyncResponse response = (ExecuteAsyncResponse)sdk.Execute(request);

Enjoy!

CRM 2013 – JavaScript Alerts and Confirmations

The Xrm.Utility library in Dynamics CRM 2013 provides new functions to display alerts and confirmations in CRM forms. In previous versions of CRM, you would have to use the alert() and confirm() JavaScript functions, but these are now supported in the CRM 2013 SDK with some additional options.

Xrm.Utility.alertDialog

This function takes in two parameters:

message: The message you wish to display in the alert.

onCloseCallBack: A function to execute when the user clicks on OK or closes the alert window using the X button.

Example:

The following code will display an alert and then will set the First Name field of a Contact to “Frosty” when the user clicks on OK.

CRM2013.showAlert = function () {

Xrm.Utility.alertDialog(“This will set the First Name to ‘Frosty'”, function () {

Xrm.Page.getAttribute(“firstname”).setValue(“Frosty”);

});

}

clip_image002

clip_image004

Xrm.Utility.confirmDialog

This function takes in three parameters:

message: The message you wish to display in the alert.

yesCloseCallback: A function to execute when the user clicks on Yes.

noCloseCallback: A function to execute when the user clicks on Cancel.

Example:

The following code will prompt the user to confirm if they want to save the form. If they select Yes, the form will save. If they select Cancel, the Email Address field will have focus set.

CRM2013.showConfirmation = function () {

Xrm.Utility.confirmDialog(“Are you sure you want to save this record?”,

function () {

Xrm.Page.data.entity.save();

},

function () {

Xrm.Page.getControl(“emailaddress1”).setFocus();

});

}

clip_image006

It is great to see native JavaScript functions being added to the Dynamics CRM 2013 SDK. This means that you can still achieve the same functionality but in a totally supported manner.

CRM 2013 – Toggle Time Portion of Date Fields

The Xrm.Page.ui.control namespace of the Microsoft Dynamics CRM 2013 SDK provides a new function to programmatically show or hide the time portion of a Date and Time field in a supported manner. Here’s how!

To show both the date and time portion of a Date and Time field:

Xrm.Page.getControl(“ros_date”).setShowTime(true);

clip_image001

To hide only the time portion of a Date and Time field:

Xrm.Page.getControl(“ros_date”).setShowTime(false);

clip_image002

Unfortunately, there are no SDK functions to allow you to show only the time portion of a Date and Time field, however you can achieve this using unsupported customizations.