Sitemap

Tuesday, November 14, 2017

Set session timeout in MS CRM

By default online session timeout is 1440 minutes or 24 hours. We can configure or set session timeout as per requirement as shown below.

Go to settings->Adminstration->System settingss->General Tab.


Under Set session timeout section, click on Set Custom radio so that, below text boxes will be enabled for you to set session timeout.


Entity Change Tracking in MS CRM

Change Tracking is usefull when we are synching the data with external sources. Earlier it was very difficult to track or maintain the changes since last synchronized. With small piece of code and samll setting it will be very easy now.

By selecting, or deselecting, change tracking for specific entities you can reduce the load on your server resources and save processing time when extracting Dynamics 365 data and synchronizing it to an external store. You can enable change tracking for both system and custom entities


  1. Go to Customizations > Customize the System.
  2. Select an entity, and under Data Services, select the Change Tracking check box.














string token;

            // Initialize page number.
            int pageNumber = 1;
            List<Entity> initialrecords = new List<Entity>();

            // Retrieve records by using Change Tracking feature.
            RetrieveEntityChangesRequest request = new RetrieveEntityChangesRequest();
            request.EntityName = _customBooksEntityName.ToLower();
            request.Columns = new ColumnSet("sample_bookcode", "sample_name", "sample_author");
            request.PageInfo = new PagingInfo() { Count = 5000, PageNumber = 1, ReturnTotalRecordCount = false };


            // Initial Synchronization. Retrieves all records as well as token value.
            Console.WriteLine("Initial synchronization....retrieving all records.");
            while (true)
            {
                RetrieveEntityChangesResponse response = (RetrieveEntityChangesResponse)_serviceProxy.Execute(request);

                initialrecords.AddRange(response.EntityChanges.Changes.Select(x => (x as NewOrUpdatedItem).NewOrUpdatedEntity).ToArray());
                initialrecords.ForEach(x => Console.WriteLine("initial record id:{0}", x.Id));
                if (!response.EntityChanges.MoreRecords)
                {
                    // Store token for later query
                    token = response.EntityChanges.DataToken;
                    break;

                }
                // Increment the page number to retrieve the next page.
                request.PageInfo.PageNumber++;
                // Set the paging cookie to the paging cookie returned from current results.
                request.PageInfo.PagingCookie = response.EntityChanges.PagingCookie;
            }


We need to store token for later query. Below are the constraints of entity change.

  1. Only one entity will be tracked in retrieve changes. If retrieve changes is executed with no version / or token, the server will treat it as the system minimum version, returning all of the records as new. Deleted objects won’t be returned.
  2. Changes will be returned if the last token is within a default value of 90 days. If it is more than 90 days, the system will return all the records.
  3. If a client has a set of changes for an entity, say version 1, a record is created and deleted prior to the next query for changes, they will get the deleted item even if they didn’t have the item to begin with.
  4. Records are retrieved in the order determined by server side logic. Usually, the end user will always get all new or updated records first (sorted by version number) followed by deleted records.  If there are 3000 records created or updated and 2000 records deleted, Dynamics 365 returns a collection of 5000 records, which have the first 3000 entries comprised of new or updated records and the last 2000 entries for deleted records.
  5. If the new or updated item collection is greater than 5000, the user can page through the collection.

Prevent auto save in MS CRM

By default auto save is enabled in organization level. We can disable auto save in organization level or form level using small script.

Disabling auto save in organization level:
  1. Go to Settings > Administration.
  2. Choose System Settings.
  3. For the Enable auto-save for all forms option, select No.

Disable auto save in form level:

As there is no setting to disable auto save for a form we have to write down small piece of code as shown below. And register the method on onsave and don't forget to check Pass execution context as first parameter

function preventAutoSave(econtext) {
    var eventArgs = econtext.getEventArgs();
    if (eventArgs.getSaveMode() == 70 || eventArgs.getSaveMode() == 2) {
        eventArgs.preventDefault();
    }
}


We have to repeat the same process for the all the forms on which we want to disable autosave. 70 is the save mode for Auto save.

Below are the some interesting points about autosave.

  1. Form will automatically be saved thirty seconds after the change is made.
  2. The field that someone is currently editing isn’t included in an auto-save
  3. If someone else has updated the same record while you’re editing it, those changes will be retrieved and displayed in the form when auto-save occurs.
  4. When auto-save is enabled the record will be saved whenever you navigate away from a record or close a separate window displaying a record.

Thursday, November 2, 2017

Vector Format or Scalable Vector Graphics web resource in MS CRM Dynamics 365 9.0

Dynamics 365, version 9.0 introduced a new Image web resource called Vector Format  (SVG). SVG stands for Scalable Vector Graphics an XML-based vector image format. This is very useful for any icon presented in application. Earlier we have to define multiple of image with  different sizes to set an icon. Now, with Vector image you can define one vector image and re-use it rather than provide multiple sizes of images.

Friday, October 27, 2017

Test Database Connection

There are different ways to test database connection like SQL management studio or some C# code , but here we will talk about alternative way of testing database connection using UDL file.

Create a empty text file, I have given a name as databaseconnection.txt.








Now change the extension of .txt  to .udl, it will throw an alert and click yes. Now file will be looks like below.








Now open the file.












































By passing the all the details over there you can test your data base connection.

Friday, October 6, 2017

Encrypt or Decrypt connection string in .Net

Connectionstring contains highly confidential information which we should secure carefully to prevent any kind of misuse., To secure this confidential information we don't need to write any addition code as we can do with ease in .Net. Below are the steps to encrypt and decrypt connection string.


Let assume you have a connection string as follows either in web.config or app.config.


Now go to below path to access aspnet_regiis.exe
"%WinDir%\Microsoft.NET\Framework\<versionNumber>"

And run below command

aspnet_regiis -pe "connectionStrings" -app "/MyApplication"

The above command with -app switch assumes that there is an IIS virtual directory called MyApplication. If you are using the Visual Studio .NET 2005 Web server instead of IIS, use the -pef switch, which allows you to specify the physical directory location of your configuration file.

aspnet_regiis.exe -pef "connectionStrings" C:\Projects\MyApplication

Note: As above command only looks for web.config, change your app.config name to web.config if you are using windows or console application. Don't worry you will change your config name back to app.config once this process is done.

If everything is fine then you will see below message in command prompt.




And your app.config or web.config will be like below.












You can use below code to retrieve conntionstring, as ConfigurationManager will take care of decrypting the password.

string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["testConn"].ConnectionString;


That’s all to maintain secure connection string in web.config or app.config.

Note   If your ASP.NET application identity does not have access to the .NET Framework configuration key store, the following message is returned:

Parser Error Message: Failed to decrypt using provider 'RsaProtectedConfigurationProvider'.
 Error message from the provider: The handle is invalid.
 
To grant access to the ASP.NET application identity
  1. If you are not sure which identity to use, check the identity from a Web page by using the following code:
    using System.Security.Principal;
    ...
    protected void Page_Load(object sender, EventArgs e)
    {
      Response.Write(WindowsIdentity.GetCurrent().Name);
    }
     
  2. By default, ASP.NET applications on Windows Server 2003 run using the NT Authority\Network Service account. Open a .NET command prompt, and use the following command to give this account access to the NetFrameworkConfigurationKey store:
    aspnet_regiis -pa "NetFrameworkConfigurationKey" "NT Authority\Network Service"
    If
     the command runs successfully you will see the following output:
    Adding ACL for access to the RSA Key container...
    Succeeded!
     
    You can check the ACL of the file in the following folder:
    \Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys
    Your 
    RSA key container file is the file in this folder with the most recent timestamp.



To change the connectionStrings section back to clear text, run the following command from the command prompt:
aspnet_regiis -pd "connectionStrings" -app "/MyApplication"
If the command is successful, you will see the following output:





To decrypt the connectionStrings section that specifies a physical path to your application's configuration file, use the -pdf switch as shown here.
aspnet_regiis -pdf "connectionStrings" C:\Projects\MyApplication