Search This Blog

Monday, June 29, 2015

Business Rule Limitations in CRM

Business Rule Limitations in CRM

Before knowing the limitation,Look how business rule work in CRM.
http://alagunellaikumar.blogspot.in/2016/03/business-rule-in-crm.html
  1. Business rules run only when the form loads and when field values change. They do not run when a record is saved, unless the scope for the rule is set at an entity level(server side execution).
  2. Business rules work only with fields. If you need to interact with other visible elements, such as tabs and sections, within the form you need use form scripts.
  3. When you set a field value by using a business rule, any OnChange event handlers for that field will not run. This is to reduce the potential for a circular reference, which could lead to an infinite loop.
  4. If a business rule references a field that is not present on a form, the rule will simply not run. There will be no error message.
  5. Whole Number fields that use the formats for TimeZone, Duration, or Language will not appear in the rule editor for the conditions or actions, so they cannot be used with business rules.
  6. Business rules only work client side, so won’t be triggered when data is changed server side (plugins, workflows, import)
  7. Business rules can set value to lock field/read only but when save it value not saved because you have to manually give force submit for the field. 
  8. Logic in business rules is applied. When there are multiple business rules, they are applied in the order they were activated, from oldest to newest  or Business rules are run in order of activation

When you set the value of a lookup field, the text of the primary field value that is set in the form will always match the text that is visible in the rule definition. If the text representing the primary field value of the record you are setting in the lookup changes, the value set by your rule will continue to use the text portion of the primary field value defined by the rule. To fix this, update the rule definition to use the current primary name field value.

Lookup Value set
It is useful to understand that the value set for a lookup has three parts:

Name: The text of the primary field value you see in the form.

Id: The unique identifier for the record. This is the data that is saved. This is not visible in the form.

LogicalName: The name of the entity, such as contact, account, or opportunity.

The rule will set all three parts of this value. The Id value for a specific record never changes, but the Name value might change.


For example, if you define a rule to set a lookup to a contact that has the Full Name of ‘Old Name’, this text is the Name you will see in the lookup when it is set by your business rule even if someone later changes the Full Name of the contact to ‘New Name’. The lookup Id value will be correctly set to the expected record, but the Name (which is not saved) will reflect the rule definition value rather than the current Full Name value of the record it references.

Please refer below site for more information:
https://community.dynamics.com/crm/b/crmbusiness/archive/2014/10/27/crm-2013-business-rule-workings-limitations-and-exam-notes

Thursday, June 25, 2015

Access Quick View Form fields – Dynamics CRM 2015

Access  Quick View Form fields

If you have any doubt in the post please post comments. I will try to solve your problem.

           Quick view forms in Dynamics CRM 2013 allow you to display all the related entity information.
Is there a way to retrieve the field value on Quick View Form using JavaScript without additional

OData call to the associated entity?
The answer is Yes and here is the sample of the form and JavaScript:

  Here is the Following steps to get the value from the QuickView form

Sample Quick Form  
  Eg: We need to get the attribute value called AccountNumber from QuickForm

Step 1:

Open the Customization->Entity->Form

Step 2:
Double click the customer pane window to see the properties and note the quickformname,and related entity name.Click Edit.
    


Step 3:
  Our goal is to get the attribute name of AccountNumber.
  After Click Edit the following dialog box with Field Properties and note down the attribute name
Code:

Syntax
QuickFormname_QuickFormname_EntityName_AttributeName

Example:
if(Xrm.Page.getControl('customerpane_qfc_customerpane_qfc_account_accountnumber') != null) {
            var caseCustomerPanectrl = Xrm.Page.getControl('customerpane_qfc_customerpane_qfc_account_accountnumber');
            strAccountNo = caseCustomerPanectrl.getAttribute('accountnumber').getValue();
        }


Well its is easily done without any stuff!!!!

Monday, June 22, 2015

Auto Mapper in MVC:

Auto Mapper in MVC:

When we code for a realistic actual environment, we encounter many challenges to refractor our code for a better understanding and to easily identify the bugs. We mainly focus on re usability and try to move as much code as possible to a common method so that development time and maintenance costs are reduced.
         In this article, I will try to cover a new concept in MVC:  AutoMapper is used to reduce the complexity we find when binding the model and communicating with entities.

The Real Problem: 
We often interact with our database entities and bind our models with it. What we end up with is somewhat like this:
//Return UserDTO Class
public UserDto GetUserById(string id)
{
//Create new Object for DTO class
var userDto = new UserDto();
//Create New Object For Entity(DB class)
using(var context = new EntityDBContext())
{
//Get the single row from DB using LINQ query
//It always use using statement for best practice to dispose object automatically
var user = context.Users.Where(ID => ID.user_id == id).FirstOrDefaul();
if (user != null)
{
//Fill DB object to UserDTO Class
userDto.UserId = user.user_id;
userDto.Name = user.user_name;
userDto.Address = user.user_address;
userDto.PhoneNo = user.user_phoneNo;
userDto.City = user.user_city;
}
}
return userDto;
}   

We see here that there are five properties in each class. And what we are doing here is binding the db context class to our model and then passing it to the view. Now, this looks quite simple in this case. The real problem arises when we have 25-30 fields in a record from the database and we need to repeat this same binding code all over in the project. It's awkward and painful. Copying and pasting even if it's only five properties.
                     More complexity arises when we have a separate ViewModel for each view (which is typically used in current MVC across the companies). Now you have double the amount of work, first you need to bind your model and then again you need to bind it to the ViewModel. Think of how tedious that job would be.
                To overcome this tedious situation AutoMapper is introduced. It not only reduces the effort but it also limits the execution time that has been taken by such a large number of lines to execute.

What is AutoMapper:

  AutoMapper is an object-object mapper. Object-object mapping works by transforming an input object of one type into an output object of a different type. What makes AutoMapper interesting is that it provides some interesting conventions to take the dirty work out of figuring out how to map type A to type B. As long as type B follows AutoMapper's established conventions, almost zero configuration is needed to map two types." Therefore, it provides the solution for our mapping issue.
   

   Firstly install the NuGet Package Manager in your Visual Studio IDE. Once done, go to:
     Tools -> Library Packet Manager -> Packet manager Console
Then in the console window opened at the bottom of Visual Studio, type:
                  PM> Install-Package AutoMapper
Press Enter, this will install AutoMapper and the next time you open an MVC application in Visual Studio, it will automatically add a DLL reference to the project.

Use of Automapper:

Now we will see where AutoMapper fits in our problem. Well, AutoMapper provides a CreateMap<T1,T2> method that provides mapping between two classes. So, the entire code can be replaced by the following single line:
There are two steps to use this Automapper

Step 1 :

//UserDTO-DTO Object Class//User-Model Class to bind the View//Fill UserDTO to User model

                           Mapper.CreateMap<User, UserDto>();
Step 2 :
                          Mapper.Map<User,UserDto >(user);
Where User is a DBContext class type and UserDto is our DTO class to map.

Finally:to map all the data we need to use the Map<T1,T2>() method of the AutoMapper class. So the final code will look like this:


public UserDto GetUserById(string id)
{
var userDto = new UserDto();
using(var context = new EntityDBContext())
{
var user = context.Users.Where(ID => ID.user_id == id).FirstOrDefault();
//Create Map for DTO and Model Object
Mapper.CreateMap<User,UserDto >();
//Fill the DTO object to Model Object and reduce the lot of code.
userDto = Mapper.Map<User,UserDto >(user);
}
return userDto;
}
So, we avoided the boring work of mapping properties in the code. Our CRUD operation is also simplified and organized. Just map the classes and then do Post actions. To get all the details, one change we need to make to the preceding code is that we need to add all the userDto objects to a List of userDtos.
   

ForMember() and MapFrom() in AutoMapper

Two important functions in AutoMapper play an important role in object mapping. Suppose our model/viewmodel class has a property FullName, and from the DTO we want to add the First Name and Last Name of the user to make it a full name and bind it to the model. For these kinds of scenarios ForMember() andMapFrom() come in handy. See below code:
   Mapper.CreateMap<LearningMVC.User, LearningMVC.Models.User>().ForMember(emp => emp.Fullname,
map => map.MapFrom(p => p.FirstName + " " + p.LastName));

Here we are saying that ForMember FullName in our model class maps properties from FirstName and LastName of User DTO.

The code itself is self-explanatory. This kind of mapping is also called Custom Mapping.




Wednesday, June 17, 2015

Masking control in CRM 2015

Password Masking in CRM 2015

If you have any doubt in the post please post comments. I will try to solve your problem.

In CRM there is no default password masking, we have to manually write a java-script code to achieve it.

We have to mask Password and some other control based on our requirement. Here i was masked password and license key.
Solution:
There are two ways to achieve it.
a) we can give field level security
b) Using javascript we can hide.

Field Level Security
If you give field level security, We have to give all roles create rights and disable edit rights.but system administrator can view this field any time.

Javascript
Even system administrator also not able to see in edit mode. We have full control on our code.

1) Create new column as password masking(new_passwordmasked).
2) Place the column in the CRM form
3) Write a "OnSave" event code in the form.
     Get the value from password control and masked that value and save it in another control.

  var Password = Xrm.Page.getAttribute("new_password").getValue();
       if(Password != null){
                  Xrm.Page.getAttribute("new_passwordmasked").setValue(Password.replace(/.+/, "************"));
        }
  Using regex we masked the password control
4) Write "onLoad" event in form to enable and disable the password and masked password control.


   if (Xrm.Page.ui.getFormType() == 1) {
       Xrm.Page.getControl("new_password").setVisible(true);
       Xrm.Page.getControl("new_passwordmasked").setVisible(false);
   } else {
       Xrm.Page.getControl("new_password").setVisible(false);
       Xrm.Page.getControl("new_passwordmasked").setVisible(true);

   }
Here we are enable and disable the control based on the form type because in new mode we have to show password control and it edit mode we have to show "masked password control".

Why do we need two control?
Because you may use this password control value from another form. In that you need extact value not masked value. That's why we are using two control.

We are not encoded or encrypt the password value,just replace the value as *.

Tuesday, June 16, 2015

Regex

Masking credit card number:
In credit card there are totally 16 digits, first 12 is masked as * and last 4 has to be displayed 
Pattern:
/\d{12}(\d{4})/
\d-Digit
X{n}-Matches any string that contains a sequence of X n's
Example:
 var strMaskedName=strName.replace(/\d{12}(\d{4})/, "**** **** **** $1");

Masked all string and digit in the input field.
Pattern:
/.+/

Example:
var Name="Alagu@123":
var strname=Name.replace(/.+/, "************");

Source control in CRM 2011,2013,2015

Source control in CRM 2011,2013,2015

If you have any doubt in the post please post comments. I will try to solve your problem.

When you export solution it save as .zip file. It is very difficult to track the recent changes in the zip files.

The Solution Packager is a excellent tool to track the changes in source control. It simply convert zip file into multiple files(individual components files/folder). Add and submit these file to your source control.

Download CRM2015 SDK file,extract it and find "SolutionPackager" exe in {folder}\SDK\bin\SolutionPackager

Using the Solution Packager:

The .exe is a command line tool. It works with both managed and unmanaged solutions, and the parameters it takes depends on whether you are fragmenting the .zip file into folders/files or creating a .zip file.

From the command line, here is how you would extract the files/ folders from the .zip file:
Syntax:
SolutionPackager /action: Extract /zipfile: <location of unmanaged .zip file> /folder: <folder where the .zip is extracted to>
Argument
Description
/action: {Extract|Pack}
The action to perform, this can be either: Extract a solution .zip file to a folder, or Pack a folder into a .zip file.
/zipfile: <file path>
The path and name of a CRM Solution .zip file. When extracting this file must exist and will be read from. When packing this will be replaced.
/folder: <folder path>
The path to a folder. When extracting this folder will be created and populated with component files. When packing this folder must already exist and contain previously extracted component files.
Example:
 I have a solution file called PHRS_1_0_0_1.zip. I am going to extract in to D:\VSS\ folder.
Extract file from zip file:
SolutionPackager.exe /action: Extract /zipfile: D:\Solutions\PHRS_1_0_0_1.zip /folder: D:\VSS\



Pack file again and convert to zip file:
SolutionPackager.exe /action: Pack /zipfile: D:\VSS\Test.zip /folder: D:\VSS

Once you extract the zip file, submit those file in source control.If there is an updated version of the file to reconcile the conflict by communicating with the team member regarding the change. If there is no conflict, upload the latest files to Source Control.


Monday, June 15, 2015

Update the plugin in MS CRM 2015

Update the plugin in MS CRM 2015

If you have any doubt in the post please post comments. I will try to solve your problem.

1) Open the plugin registration tool and select the plugin that you want to update. Click update 
     button.



2) Click lookup button and select plugin dll that you want to update.



3) Checked the plugin and click "Sandbox" mode as isolation mode and click "Tab" two times(because there is no "Ok" button in the screen).



Sunday, June 14, 2015

How to Register Plugin in CRM

How to Register Plugin in CRM

If you have any doubt in the post please post comments. I will try to solve your problem.

You can register plugin through "Plugin  Registration.tool". You can download from https://www.microsoft.com/en-us/download/details.aspx?id=44567.

Run pluginRegistration.exe in SDK\Tools\PluginRegistration\PluginRegistration.exe

1) Click "CreateNewConnection".If you have multiple select organisation and login.

2)Click register new assembly
3)  Click the lookup and choose the dll. Select "Sandbox" as isolation mode and select "database" to store the assembly and click tab two times and click enter(Because there is no button in that form).


4) Now assembly is successfully registered. We have to create step. To find message name and entity
In the Plugin Registrtion SDK folder, there is file name called "Message-entity support for plug-ins".




Write Plugin code in CRM

Write Plugin code in CRM

If you have any doubt in the post please post comments. I will try to solve your problem.

Plug-ins are custom classes that implement the IPlugin interface. You can write a plug-in in any .NET Framework 4.5.2 CLR-compliant language such as Microsoft Visual C# and Microsoft Visual Basic .NET. To be able to compile plug-in code, you must add Microsoft.Xrm.Sdk.dll and Microsoft.Crm.Sdk.Proxy.dll assembly references to your project. These assemblies can be found in the SDK\Bin folder of the SDK. Download the Microsoft Dynamics CRM SDK package.

using System;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;

public class MyPlugin: IPlugin
{
    public void Execute(IServiceProvider serviceProvider)
    {
        // Extract the tracing service for use in debugging sandboxed plug-ins.
        // If you are not registering the plug-in in the sandbox, then you do
        // not have to add any tracing service related code.
        ITracingService tracingService =
            (ITracingService)serviceProvider.GetService(typeof(ITracingService));

        // Obtain the execution context from the service provider.
        IPluginExecutionContext context = (IPluginExecutionContext)
            serviceProvider.GetService(typeof(IPluginExecutionContext));

        // The InputParameters collection contains all the data passed in the message request.
        if (context.InputParameters.Contains("Target") &&
            context.InputParameters["Target"] is Entity)
        {
       



}
     }

}

Types of Entities in CRM

Types of Entities in CRM

If you have any doubt in the post please post comments. I will try to solve your problem.

There are three types of entities in CRM.

  1. System entities -Cannot edit by user
  2. Business entities-Can add column by user
  3. Custom entities-Can create new entity by user

Saturday, June 13, 2015

SQL query for Retrieve method(query expression) in plugin using SQL Profiler

SQL query for Retrieve method(query expression) in plugin using SQL Profiler

If you have any doubt in the post please post comments. I will try to solve your problem.

In plugin to get the data for another entity, we normally used query expression. When you used filter expression and condition in the query expression. It is little bit difficult to understand how the query forms.

Solutions:
Open SQL profiler and connect the database and run the trace. All the plugin is run by crmservice user. when you search in the profiler you will get the query, how SQL query form and execute.

1) Open the SQL profiler
2) Open the trace and give trace properties to catch the SQL query
3) Put ctrl+f find window pop up, give the table name and click.Now you can get query format





Friday, June 12, 2015

Address automatically created when create account or contact.How to handle automatically create address

If you have any doubt in the post please post comments. I will try to solve your problem.

When Account and contact is create, two addresses automatically created. If you create plugin for address(customeraddress),plugin will not fire for those addresses for the below configuration.

For example:
Set address name as account name for address
Solutions:
Create a plugin for account and configure it as post operation. On the account  plugin, get/retrieve the address based on account id (where parentid=accountid). Iterate the address assign address name as account name and update the address as
service.update(objAddressEntity).

The same thing you can configure it for contact.

Wednesday, June 10, 2015

Invalid cast exception in CRM plugin

Invalid cast exception in CRM plugin

If you have any doubt in the post please post comments. I will try to solve your problem.

In plugin if it throws invalid cast exception then you have to check what are the values assigned to the entity is miss match. The input attributes please check..
1)Entityreference --Proper entity reference with logical entity,name and id.
2)Optionset -- have to pass value(unique no) not name
3)Check box --have to pass as true and false

One more way to solve the issue, If you update the entity then get the data using query expression, in which pass attribute name that you are going to give input then check what values are come from the entity and compare with your existing code.

Jquery Cons and Pros in Microsoft CRM 2015

Use jQuery with HTML web resources
We recommend that you use jQuery together with HTML web resources to provide user interfaces because it is an excellent cross-browser library.
With HTML web resources, you control the libraries that are present and there is no restriction against manipulating the DOM. Feel free to use jQuery within your HTML Web resources.
Avoid using jQuery with form scripts or ribbon commands
We do not recommend using jQuery in form scripts and ribbon commands.
Most of the benefit provided by jQuery is that it allows for easy cross-browser manipulation of the DOM. This is explicitly unsupported within form scripts and ribbon commands. Restrict your scripts to use the Xrm.Page and Xrm.Utility libraries available in form scripts and ribbon commands. If you decide to use the remaining capabilities of jQuery that are useful with Microsoft Dynamics CRM and include the ability to use $.ajax, consider the following:
·         For best performance, don’t load jQuery in the page if you do not need it 
·         Using $.ajax to perform requests against the OData and Modern Apps SOAP endpoint is supported, but there are alternatives. The alternative to using $.ajax is to use the browsers XMLHttpRequest object directly. The jQuery $.ajax method is just a wrapper for this object. If you use the native XMLHttpRequest object directly, you do not need to load jQuery.

Compare the SDK.REST.js and SDK.JQuery.js sample libraries found in Sample: Create, retrieve, update, and delete using the OData endpoint with JavaScript and Sample: Create, retrieve, update, and delete using the OData endpoint with JavaScript and jQuery. Both perform the same operations, but SDK.REST.js doesn’t require jQuery.
·         Each version of jQuery that is loaded in a page can be a different version. Different versions of jQuery have different behaviors and these can cause problems when multiple versions of jQuery are loaded on the same page. There is a technique to mitigate this, but it depends on editing the jQuery library and any other libraries that depend on jQuery. More information: jQuery and jQuery UI with Dynamics CRM 2011 & 2013jQuery.noConflict()


Javascript functions/Reference in Microsoft CRM 2013 and 2015

The JavaScript object model is the JavaScript API that CRM provides to enable you to customize various behaviors based on events and to access CRM data that is present on a form.

Xrm.Utility: Xrm.Utility object provides a container for useful functions not directly related to the current page. The following table lists the functions of Xrm.Utility.

Xrm.Utility
alertDialog
Displays   a dialog box with a message.
confirmDialog
Displays   a confirmation dialog box that contains a message as well as OK and Cancel   buttons.
isActivityType
Determine   if an entity is an activity entity.
openEntityForm
Opens   an entity form.
openWebResource
Opens   an HTML web resource.

Xrm.Page.data: Xrm.Page.data provides an entity object that provides collections and methods to manage data within the entity form.
 The following tables lists the functions ofXrm.Page.data and Xrm.Page.data.entity
Xrm.Page.data
getIsValid*
Do a validation check for the data in   the form.
refresh*
Asynchronously refresh all the data of the form without reloading the page.
save*
Saves the record asynchronously with the option to set callback functions.
Xrm.Page.data.entity
addOnSave
Adds a function to be called when the record is saved.
getDataXml
Returns a string representing the xml that will be sent to the server when the record is saved.
getEntityName
Returns a string representing the  logical name of the entity for the record.
getId
Returns a string representing the GUID   id value for the record.
getIsDirty
Returns a Boolean value that indicates if any fields in the form have been modified.
getPrimaryAttributeValue*
Gets a string for the value of the primary attribute of the entity.
removeOnSave
Removes a function to be called when the record is saved.
save
Saves the record with the options to close or new.
Xrm.Page.context: Xrm.Page.context provides methods to retrieve information specific to an organization, a user, or parameters that were passed to the form in a query string. The following table lists the functions of Xrm.Page.context.
 Xrm.Page.context
client.getClient*
Returns a value to indicate which client the script is executing in.
client.getClientState*
Returns a value to indicate the state of the client.
getClientUrl
Returns the base URL that was used to access the application.
getCurrentTheme
Returns a string representing the current Microsoft Office Outlook theme chosen by the user.
getOrgLcid
Returns the LCID value that represents   the base language for the organization.
getOrgUniqueName
Returns the unique text value of the   organization’s name.
getQueryStringParameters
Returns a dictionary object of key   value pairs that represent the query string arguments that were passed to the   page.
getUserId
Returns the GUID of the SystemUser.Id value for the current user.
getUserLcid
Returns the LCID value that represents the provisioned language that the user selected as their preferred language.
getUserName*
Returns the name of the current user.
getUserRoles
Returns an array of strings that represent the GUID values of each of the security roles that the user is  associated with.
isOutlookClient
(Deprecated) Returns a Boolean value indicating if the user is using Microsoft Dynamics CRM for Outlook.
isOutlookOnline
(Deprecated) Returns a Boolean value that indicates whether   the user is connected to the CRM server.
prependOrgName
Prepends the organization name to the   specified path.
Xrm.Page.ui:  Xrm.Page.ui provides collections and methods to manage the user interface of the form. The following table lists the functions of Xrm.Page.ui
Xrm.Page.ui
clearFormNotification*
Remove form level notifications.
close
Method to close the form.
formSelector.getCurrentItem
Method to return a reference to the   form currently being shown.
formSelector.items
A collection of all the form items accessible to the current user.
getViewPortHeight
Method to get the height of the viewport in pixels.
getViewPortWidth
Method to get the width of the viewport   in pixels.
getCurrentControl
Get the control object that currently has focus.
getFormType
Get the form context for the record.
navigation.items
A collection of all the navigation items on the page.
setFormNotification*
Display form level notifications.
refreshRibbon
Re-evaluate the ribbon data that controls what is displayed in it.
 Collections
Xrm.Page.data.entity.attributes
All attributes on the page.
Xrm.Page.ui.controls
All controls on the page.
Xrm.Page.ui.formSelector.items
All the forms available to the user.
Xrm.Page.ui.navigation.items
All the items in the form navigation   area.
Xrm.Page.ui.tabs
All the tabs on the page.
Xrm.Page Attribute.controls
All the controls for the attribute.
Xrm.Page.ui Section.controls
All the controls in the section.
Xrm.Page.ui Tab.sections
All the sections in the tab.
 Collections Methods
forEach
Apply an action in a delegate function to each object in the collection.
get
Get one or more object from the collection depending on the arguments passed.

Attributes: Attributes store the data available in the record. Attributes are available from theXrm.Page.data.entity.attributes collection. To access an attribute you can use theXrm.Page.data.entity.attributes.get method or the shortcut version Xrm.Page.getAttribute. Following table shows how you can query attribute properties to understand what kind of attribute it is or change the behavior of the attribute.
 Xrm.Page.getAttribute(“…”)
getAttributeType
Get the type of attribute.
getFormat
Get the attribute format.
getIsDirty
Determine whether the value of an   attribute has changed since it was last saved.
getIsPartyList
Determine whether a lookup attribute   represents a partylist lookup.
getMaxLength
Get the maximum length of string which   an attribute that stores string data can have.
getName
Get the name of the attribute.
getParent
Get a reference to the Xrm.Page.data.entity object that is the parent to all attributes.
getRequiredLevel
Returns a string value indicating   whether a value for the attribute is required or recommended.
getSubmitMode
Sets whether data from the attribute   will be submitted when the record is saved. always / never / dirty
getUserPrivilege
Determine what privileges a user has   for fields using Field Level Security.
getValue / setValue
Gets or Sets the data value for an   attribute.
setRequiredLevel
Sets whether data is required or   recommended for the attribute before the record can be saved. none / required  / recommended
setSubmitMode
Returns a string indicating when data   from the attribute will be submitted when the record is saved.
Number Attribute Methods
getMax / getMin
Returns a number indicating the maximum   or minimum allowed value for an attribute.
getPrecision
Returns the number of digits allowed to   the right of the decimal point.
setPrecision*
Override the precision set for a number attribute.
DateTime Attribute Methods
setIsAllDay*
Specify whether a date control should  set a value including the entire day.
setShowTime*
Specify whether a date control should  show the time portion of the date.

Controls: Controls represent the user interface elements in the form. Each attribute in the form will have at least one control associated with it. Not every control is associated with an attribute. IFRAME, web resource, and subgrids are controls that do not have attributes. Controls are available from the Xrm.Page.ui.controls collection. To access a control you can use the Xrm.Page.ui.controls.get method or the shortcut version Xrm.Page.getControl. 
The following table lists the functions of Controls.

Xrm.Page.getControl(“…”)  
clearNotification*
Remove a message already displayed for   a control.
getAttribute
Get the attribute that the control is   bound to.
getControlType
Get information about the type of   control.
getDisabled / setDisabled
Get or Set whether the control is   disabled.
getLabel / setLabel
Get or Set the label for the control.
getName
Get the name of the control.
getParent
Get the section object that the control   is in.
getVisible / setVisible
Get or Set a value that indicates   whether the control is currently visible.
setFocus
Sets the focus on the control.
setNotification*
Display a message near the control to   indicate that data is not valid.

Lookup Controls: The following table lists the functions of Lookup Control.
addCustomFilter*
Use fetchXml to add additional filters   to the results displayed in the lookup. Each filter will be combined with an   ‘AND’ condition.
addCustomView
Adds a new view for the lookup dialog   box.
addPreSearch*
Use this method to apply changes to   lookups based on values current just as the user is about to view results for   the lookup.
getDefaultView / setDefaultView
Get or Set Id value of the default   lookup dialog view.
removePreSearch*
Use this method to remove event handler

OptionSet: The following table lists the functions of OptionSet Control.

getInitialValue
Returns a value that represents the   value set for an optionset or boolean when the form opened.
getOption[s]
Returns an option object with the value   matching the argument passed to the method.
getSelectedOption
Returns the option object that is selected.
getText
Returns a string value of the text for   the currently selected option for an optionset attribute.
adoption / removeOption
Adds or remove an option to an option   set control.
clearOptions
Clears all options from an Option Set   control.

IFRAME and Web Resource Controls:  An IFRAME control allows you to include a page within a form by providing a URL. An HTML web resource added to a form is presented using an IFRAME element. Silverlight and image web resources are embedded directly within the page. The following table lists the functions of IFrame or Web Resource controls.

getData / setData
Get or Set the value of the data query   string parameter passed to a Silverlight web resource.
getInitialUrl
Returns the default URL that an I-frame   control is configured to display. This method is not available for web   resources.
getObject
Returns the object in the form that   represents an I-frame or web resource.
getSrc / setSrc
Get or Set the current URL being   displayed in an IFrame or web resource.

Sub-Grid Control: Sub-Grid control has refresh method. We can use this method to refresh data displayed in a Sub-Grid.

refresh
Refreshes the data displayed in a Sub-Grid.

OnChange Event: There are three methods you can use to work with the OnChange event for an attribute.

addOnChange / removeOnChange
Sets or remove a function to be called   when the attribute value is changed.
fireOnChange
Causes the OnChange event