Category Archives: Code Migration

Dynamics 365 v9.0: No More Hidden Fields

Hello everyone,

As a developer, we come across many situations where we keep a hidden field on the form only for the purpose of data manipulations. This approach always worked. However, it was difficult to keep track of what hidden fields are required on the form and by which java script web resource.

This poses two issues:

1. Sometimes we may end up accidentally removing hidden fields from forms

2. It will be a time consuming task to come up with the list of hidden fields to add on a form if we plan to reuse a web resource which uses hidden fields.

With Dynamics 365 9.0, we can avoid these situations with “Attribute Dependencies for JavaScript Web Resources”. Here is what we have to do to accomplish this. Under “Dependencies” tab of the web resource(only JScript), add attributes(so called hidden fields) to the second grid. All the attributes added in this grid are no longer required to be present on the form. When the web resource loaded on the entity form, it makes sure the dependent attributes are automatically added to the attribute collection on to the form. This allows the JScript web resource to do data manipulations without adding hidden fields to the form. One thing to note here is, these dependent attributes are only added to the attributes collection and not to the controls collection which means we cannot use “data.ui” related methods.

EntityAttList

AttList

Observations:

  1. Attribute Dependencies are only available for JScript web resources.
  2. Dependent attributes are added only to the form attribute collection. So, only attribute methods can be used.
  3. Attributes can be added from multiple entities. This is useful for the web resources reused across multiple entities.
  4. Once dependent attributes are added to attributes collection on the form, any web resource(JScript and HTML) on the form and Business Rules can use those fields for data manipulations.

Hope it helps..!!

Dynamics 365 v9.0 – Xrm.Navigation namespace methods – Part 1

Hello everyone,

Dynamics 365 v9.0 has introduced Xrm.Navigation namespace under Xrm object. It has a mix of new methods and old methods moved from Xrm.Utility.

Following is the list:

Dynamics 365 v9.0 Comments
openAlertDialog  Deprecated Method: Xrm.Utility.alertDialog
openConfirmDialog  Deprecated Method: Xrm.Utility.confirmDialog
openErrorDialog  Introduced in v9.0
openFile  Introduced in v9.0
openForm   Deprecated Methods:
Xrm.Utility.openEntityForm
Xrm.Utility.openQuickCreate
openUrl    Introduced in v9.0
openWebResource   Deprecated Method:

In this blog post, I would like to discuss about the new features added in openAlertDialog and openConfirmDialog methods.

Prior to v9.0:

Syntax:

Xrm.Utility.confirmDialog(message,yesCloseCallback,noCloseCallback)
Xrm.Utility.alertDialog(message,onCloseCallback)

Sample Code:


Xrm.Utility.confirmDialog("Are you sure you want to approve this request?",
//Confirm Dialog Success Callback
function () {
Xrm.Utility.alertDialog("Request Approved Successfully",
//Alert Dialog Ok Button Callback
function () {
//
});
},
//Confirm Dialog Close Callback
function () {
Xrm.Utility.alertDialog("Request Aborted",
//Alert Dialog Ok Button Callback
function () {
//
});
});

Result:

v9.0:

Syntax:

Xrm.Navigation.openConfirmDialog(confirmStrings,confirmOptions).then(successCallback,errorCallback);
Xrm.Navigation.openAlertDialog(alertStrings,alertOptions).then(closeCallback,errorCallback);

Following is the rewritten code for v9.0 for showing confirm and alert dialogs using openConfirmDialog and openAlertDialog methods:

function ApproveRequest() {
var confirmStrings = { title: "Approval Request", text: "Are you sure you want to approve this request?", subtitle: "This action will approve the request", confirmButtonLabel: "Approve", cancelButtonLabel: "Cancel" };
var confirmOptions = { height: 200, width: 450 };
//New v9.0 Method
Xrm.Navigation.openConfirmDialog(confirmStrings, confirmOptions).then(successCallback, errorCallback);
}

function successCallback(success) {
//On Click on Approve Button
if (success.confirmed) {
//Here Logic to Approve the Request
//
var alertStrings = { confirmButtonLabel: "Got it..!!", text: "Request Approved Successfully" };
var alertOptions = { height: 120, width: 260 };
//New v9.0 Method
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);
}
else {
var alertStrings = { confirmButtonLabel: "Got it..!!", text: "Request Cancelled" };
var alertOptions = { height: 120, width: 260 };
//New v9.0 Method
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);
}
}

function errorCallback(fail) {
//On Error Logic
}

Result:

ConfirmDialog_V9_1.png

AlertDialog_V9_1

openConfirmDialog:

Here are the improvements added in V 9.0:

  1. Better UI
  2. Ability to specify labels for confirm and cancel buttons
  3. In addition to text in the dialog title and subtitle can be added
  4. Add dialog window height and width in pixels

ConfirmDialog_V9

Note: successCallback gets called for both Confirm and Cancel Buttons. Esc and x button click as well mimics Cancel Button click. Here is how we can differentiate Confirm and Cancel button the events:

function successCallback(success) {
//success.confirmed = true for Confirm Button Click
if (success.confirmed) {
//Confirm Button Click Event Handler
}
else {
//Cancel Button Click Event Handler
}

openAlertDialog:

Here are the improvements added in V 9.0:

  1. Better UI
  2. Ability to specify labels for confirm button
  3. Add dialog window height and width in pixels

When you are upgrading to Dynamics 365 v9.0, plan to rewrite code to include these new methods.

Hope it helps..!!