Saturday, April 26, 2014

CRM 2013 - Refresh and Save functions

In CRM 2013, we have got two different functions one for saving the form and refreshing the form. Advantage of these two are that they are asynchronous in nature which can do the other activities based on the result of this refresh or save. So for example if we need to call function1 if the refresh/save was successful and function2 otherwise its pretty easy now.

We will look at refresh first,
Xrm.Page.data.refresh(save).then(
                function () {
                    //Do something if the refresh is successful
                },
                function () {
                    //Do something if the refresh is unsuccessful
                }
                );
In the above example save is a boolean value which should be used to mention whether we need to save the form after it is refreshed. If true then the form will be saved and if not then the form will not be saved.

Next we will look at the save function.
Xrm.Page.data.save().then(
                function () {
                    //Do something if the save operation is successful.
                },
                function () {
                    //Do something if the save operation is unsuccessful.
                }
                );
In both the above cases the success call back will not have any arguments. It will simply be called if the operation succeeds. At the same time error call back will be having an object with properties:
errorCode: The error code.
message: A localized error message.

One more thing to be noted for these functions are that these two are available only for updated entities.

Hope this helps!!!

Sunday, April 20, 2014

CRM 2013 - Accessing Individual attributes in a composite control

In CRM 2013, the concept of composite attributes is introduced and when the field is used in the form only the composite control will be displayed in the form. When the user has to edit this field the constituent controls will be loaded in the form of flyout controls.

We can get the values of the composite controls using getValue but for setting the value we have to access the individual fields loaded to the form.

These individual forms can be accessed directly. The naming convention followed by such fields are as follows,

<composite control name>_compositionLinkControl_<constituent attribute name>

For example if we have to access address_line1 control in address1_composite use the below code,
Xrm.Page.getControl("address1_composite_compositionLinkControl_address1_line1")

CRM 2013 - Support for tablets

You will be already aware that CRM 2013 support the tablet environment as well. From a developer point of view we need to take care that the code which we are using will also work for the tablet environment. This is because the CRM for tablets does not allow any functions that can block the execution of the scripts. Normal javascript functions like alert, confirm and prompts will not work as we expect in tablets. They will simply throw errors.

If we need to show any message to the user working in tablets then we need to use the latest functions as part of CRM SDK instead of the alerts or prompts. We have to use Xrm.Utility.alertDialog and confirmDialog functions to display messages to the user.This is because these functions do not stop the processing of scripts until the user closes them.

Similarly below are some of the examples that will not work in tablets when using CRM,
  • Xrm.Page.context.getCurrentTheme
  • Xrm.Page.data.entity.getDataXml
  • Xrm.Page.ui.formSelector object methods
  • Xrm.Page.ui.navigation.items collection
  • Xrm.Page.ui.refreshRibbon
  • Xrm.Page.ui.ViewPort methods
  • Xrm.Page.ui.control Webresource and IFRAME control methods
  • Xrm.Page.ui.tab.setDisplayState
  • Xrm.Utility.openWebResource
If opened from the tablets these functions will simply execute an empty function and return nothing. If we expect a return value from these functions it will be undefined.

So if we are customizing in CRM for tablets then its better to distinguish between the code that will run in CRM tablets

It can be done by following below steps,
  1. Get the client type (Xrm.Page.context.client.getClient())
  2. If that is "Mobile" 
  3. Then do the coding for the tablets there
  4. Else do the coding for the normal CRM scenario.
Not only the above fields, CRM for tablets implement the composite fields also in a different way than how the web application implements it. Composite fields will be substituted by the constituent attributes and display them instead.

Similar is the case for Web resources and IFRAMEs. If our code interacts with such objects we can expect that the control will not exist in a tablet CRM environment.

If you are not sure which commands will work on tablets then include a command rule which will not include such commands. 

Configuration for CRM Plugins

CRM plugins are always great feature where we can automate many functionality which we cannot automate from user interface. But almost eve...