Monday 15 December 2014

Show Loading Message during function execution or Javascript load in CRM Form.

Hey CRM Folks, Today I am going to share one very interesting task that most of CRM folks face while working in CRM and play with Javascript. Many times Customers complaint that Javascript validations are avoided because the user performs operations before JS are completely loaded.

How can I check for the Condition ?
How could i restrict user to enter anything on the CRM form while JS not get fully loaded.......

Most of the times situation occur where user asked to show some processing message during long function execution, if you are doing some processing or calling any webservice which is taking time to execute and you want to show loading messsage to user.

Javascript : 

By using below mentioned Javascript function you can show Loading Message to user and can restrict untill JS get completely loaded.

function showJSProcessingMessage() 
{
    var formdiv = document.getElementById('dummyDiv');
    formdiv.disabled = true;

    document.getElementById('tdAreas').parentElement.style.display = 'none';
    var newdiv = document.createElement('div');
    newdiv.setAttribute('id', 'msgDiv');
    //newdiv.valign = 'middle';
    newdiv.align = 'center';
    newdiv.marginBottom = '5000px';
    var divInnerHTML = "";
    divInnerHTML += "";
    divInnerHTML += "";
    divInnerHTML += "";
    divInnerHTML += "</br><img alt='' src='/_imgs/AdvFind/progress.gif' height='34px' width='34px'/></br>";
    divInnerHTML += "<b>Please wait while Script is Loading...</b>";
    divInnerHTML += "";


    divInnerHTML += "";
    newdiv.innerHTML = divInnerHTML;
    newdiv.style.color = '#001D72';
    newdiv.style.fontSize = '13px';
    newdiv.style.zIndex = '1010';
    newdiv.style.margin = '0 auto';
    newdiv.style.marginTop = '210px';
    newdiv.style.width = '270px';
    newdiv.style.height = '100px';
    newdiv.style.background = '#FFFFE4';
    newdiv.style.border = "thin solid #000000";

    //newdiv.style.width = getBrowserWidth()+'px';
    //newdiv.style.height = getBrowserHeight()+'px';
    newdiv.style.position = 'relative';
    document.body.insertBefore(newdiv, document.body.firstChild);
    document.getElementById('msgDiv').style.visibility = 'block';
   
    setTimeout(disableLoading, 10000); //use it to define ms for disable loading
    
}
function disableLoading() 
{
    if (document.readyState === "complete") 
    {
        document.getElementById('msgDiv').style.display = 'none';
        document.getElementById("tdAreas").parentElement.style.display = 'block';
        document.getElementById('dummyDiv').disabled = false;
    }

}

Use this script on form OnLoad event :

Loading Message will look like below :



Hope this will someone.....You can use it based upon your project requirement.

Enjoy and Keep Reading !!! \A/\S/

Thursday 4 December 2014

Microsoft Dynamics CRM 2015 - Start From Here !!!

Especially for CRM beginners !!!!


Finally the Most awaited one Microsoft Dynamics CRM 2015 is here!!! 

Don’t miss out the new exciting changes and enhancements that are coming! Stay up to date by reading this Blog as I continue to bring you the most up to date blog posts, other training materials relating to its highly anticipated release.2015 is ready to be the best version of Dynamics to date and I can’t wait to SHARE it with you!

See below for additional resources, information and Training Material on the Microsoft Dynamics CRM 2015 release,

Don’t forget to check out the most popular Top 10 New Features of Dynamics CRM 2015 !!!
which i'll Share in my next post...Till then,
Here is some important Links from where you can start learning....


CRM 2015 Basics :
https://onedrive.live.com/redir?resid=E596E7F6E13A3700!682&authkey=!AOjYMdaT5Cm6qy8&ithint=file%2cpdf

Start Working with CRM 2015 :
https://onedrive.live.com/redir?resid=E596E7F6E13A3700!680&authkey=!AF-2LsYBcXZkTxQ&ithint=file%2cpdf

CRM 2015 Release Preview Guide :
https://onedrive.live.com/redir?resid=E596E7F6E13A3700!681&authkey=!AKXhJLfjzuVIM5k&ithint=file%2cpdf


In my next post you'll get-


  • CRM Setup and Administration
  • Information For Developers
  • Information For End Users
  • What's new for developers
  • Product catalog enhancements
  • Use hierarchical data
  • Apply hierarchical security models
  • Use calculated and rollup attributes created in Dynamics CRM
  • Write form scripts that interact with business process flows
  • Use field-level security with system entities
  • Create business rules instead of writing code
  • Add custom help content...And Much More


So Keep Reading ...Enjoy......!!! \A/\S/

Friday 28 November 2014

“An Error Has Occurred......” while opening Custom Entity Record in CRM 2011/2013

Recently one of my colleague was facing a generic “Error has occurred” message while opening on any record of any Custom Entity in the Microsoft Dynamics CRM organization.
I also have faced this issue so many times while working in CRM, So today i would like to share the Resolution of below error so that in future anyone who is getting this error could rid of with this error :

Error :
Error while opening any record from my custom entities in crm 2011/2013.




Resolution :

This is most likely a IE Compatability issue. Add the server address in the compatability  view under IE settings:

Go to Tools, if you are not able to see Tools option in IE Press 'Alt' key from keyboard. then select 'Compatibility View settings' like below : 





























Add your organisation URL or Server Address like below:



In Somecases if you are not using Mobile form of your Custom Entities, UnCheck 'Mobile Express' option will also be the way to get rid of from this problem. see below:




Congrats you will never face this issue again........Enjoy :) \A/

Wednesday 5 November 2014

Auditing of Export to Excel in Dynamic CRM 2011/2013

Few days before I had a request from a customer that whether it is possible to find out what data(might be confidential) has been exported by a user on a specified date (for tracking or to catch culprit) on a specified date or over a period of time…
The  first thing which came into my mind was to restrict them access to “Export to Excel” on his corresponding security role but what happens to the data already exported, how to know what data was exported and stuff’s.

By done lot of Research i have found a way to get user who has exported data from CRM. Here below is the way for the same :

If you're familiar with IIS, you probably already know how to find the location of the log files, but I'll give a quick recap for those who are not. On the Microsoft CRM server, open the Internet Information Services Manager and find the Microsoft CRM website. Right-click on the website and select Properties. The following dialog will open.





Then select the Properties button, and this window will open





From here you can see that the log file directory is c:\WINDOWS\system32\LogFiles\ and the folder for this Microsoft CRM website is W3SVC1 (but yours might be different). Now launch Windows Explorer and browse to this directory. You will see a bunch of files in this folder (one for each day) named with the exyymmdd.log naming convention.

Open any of these files with the text editor of your choice. Then search in the file for the text "mode=export". If someone exported data to Excel during that day, you'll see a line that looks something like this::






The viewid of =%7BE35F1FC9-9450-455B-8F2A-5B59BA193706%7D
The IP address of 192.168.252.200
One way to determine which view of data that the viewid relates to is to browse to (entering in the name of your Microsoft CRM server and the viewid you retrieved from the IIS log file):



If you copied and pasted correctly, then you'll see the view editor for the view that a user exported! For example, if you see the view editor for the Active Leads view then you know that a user exported the data from the Active Leads view. Now that you know what data was exported, you can use the IP address to determine which computer/user did the export.



Hope this will someone !!!!! Enjoy :)

Tuesday 28 October 2014

Show MS CRM 2011/2013 Optionset values in Dropdownlist in Asp.net

I’m feeling really happy while writing this blog, because i have been too busy from last couple of months to write even a single blog. From now on, I’m hoping to keep this activity continued.

Few days back i got a very interesting requirement from one of my customer to show OptionSet values in dropdownlist in asp.net.
So we can use below code to populate optionset values in dropdownlist in asp.net Windowor Web application.

As shown below 'Stream'  field  is being showing in CRM Contact form :






public Dictionary<intstring>
RetrieveOptionsetMetadata(IOrganizationService _iOgranizationService)
{  
//Dictionary to store value and text
 Dictionary<int,string> _DropdownDatasource=newDictionary<int,string>();
 //Create request to fetch optionset
 RetrieveAttributeRequest _Request = new RetrieveAttributeRequest{
EntityLogicalName ="contact",    // Name of Entity
LogicalName =“new_stream”,    // Name of Option Set field
RetrieveAsIfPublished =true
 };
 // Execute the request
 RetrieveAttributeResponse _Response =(RetrieveAttributeResponse)_iOgranizationService.Execute(_Request);
 PicklistAttributeMetadata _PicklistAttributeMetadata = (PicklistAttributeMetadata)_Response.AttributeMetadata;
 OptionMetadata[] optionList =_PicklistAttributeMetadata.OptionSet.Options.ToArray();
 foreach (OptionMetadata _Optionset in optionList) {
_DropdownDatasource.Add(int.Parse(_Optionset.Value.ToString()), _Optionset.Label.UserLocalizedLabel.Label);
}
 return _DropdownDatasource;
}
After that we can set datasource for dropdownlist like below
DropDownList1.DataSource = RetrieveOptionsetMetadata(_iOgranizationService);
DropDownList1.DataBind();

In ASP.Net it will look like below:


Enjoy !!!

Hope this post help someone !!!

Thursday 7 August 2014

MSCRM 2011/2013 - Add Logo to CRM forms

Hello everyone today i am going to share one of the very interesting requirement that most of MSCRM guys would have faced or might be get during customization of MSCRM form...

Mostly various Customers and Clients needs to see their own Company/Organisation logo in CRM.
So today's we are going to implement the same...

Below are the easy steps to perform the same -


  • Creating Web resource
  • Upload JPG/PNG file of logo.
  • Add web resource to CRM form.
  • Adjust Layout, Positioning & Formatting.
  • Logo displayed on the Form

Creating Web resource :

first need to create web resource by going in customization in MSCRM 











Upload JPG/PNG file of logo.






















Add web resource to CRM form.



















Adjust Layout, Positioning & Formatting.



Logo displayed on the Form






Hope this post will help someone ...... 

Monday 28 July 2014

Dynamics CRM 2013 / 2011 - On Custom ribbon button click, create a new record, and open this newly created record

In this post I would like to explain how to create a new record and open the same on click of custom ribbon button in Dynamics CRM. The steps are as following:

1. Create a custom ribbon button on a specific entity, the source entity. Use the Ribbon Workbench tool or by import export the solution to add a button on this entity.


2. Create a custom attribute of type of “Two Options” on the source entity say 'new_isribbonbuttonclicked'. (specified above in step 1).

This field helps us in plug-in to identify whether the ribbon button is clicked by a user or not.

When the user clicks on this newly added button, a new record gets created via plug-in and the same will be opened in a new window with CRM 2011 or in a same window in CRM 2013.


3. Create another attribute of type “Single line text” on the same entity say new_uniqueidentifierofentity. This attribute will hold the GUID value of a newly created record.

The value of this field will be used in JavaScript/web resource code to open the newly created record.

Create a new web resource of type Script (JScript) and write the following JavaScript code in it. This code updates the value as “True” to the new_isribbonbuttonclicked attribute.

//Change the method and attribute name as per your need
    function UpdateAttribute() 
{
     var attribute = Xrm.Page.getAttribute("new_isribbonbuttonclicked"); //Specify the name of your attribute
     var attributeValue = null;
      if (attribute != null) 
 {
       attributeValue = attribute.getValue();
       if (attributeValue == null ||
           attributeValue == false) 
{
         attribute.setValue(true);
         attribute.setSubmitMode("always");
         Xrm.Page.data.entity.save();
}
      }
    }


5. Call the above JavaScript function from the ribbon button which we have created at very first step of this post.

6. Now, write a pre update plug-in on the source entity. In this plug-in just check whether the plug-in context contains the new_isribbonbuttonclicked attribute or not. If it exists in the context and the value of this attribute is “True” then create a record of another entity and get the unique identifier (GUID) of the newly created record from the response of the SDK call.

7. Then, add this GUID to the plug-in context for the new_uniqueidentifierofentity field.

Like,

entity.Attributes[new_uniqueidentifierofentity] = GUID; //Specify the name of your attribute

8. Also add the new_isribbonbuttonclicked field in the plug-in context as “False”. So that, the custom ribbon button will work for the next attempt.

9. At the end of plug-in execution the above attribute values get automatically updated.

10. Lastly, add another method in the web resource of the source entity and bind this method to “form load” event. Primarily, this method checks following two conditions.

· The form is loaded into the edit mode or not.

· The new_uniqueidentifierofentity attribute contains data or not.

If it satisfies both the conditions, meant if the record is opened in edit mode and the GUID attribute contains unique identifier of newly created record then just write a code to open this record, update the value of new_uniqueidentifierofentity to null, and save the form.


Following is the code that performs the things that we specified here in this step.


    //Change the method and attribute name as per your need
    function Form_Load() {
      if (Xrm.Page.ui.getFormType() == 2) {
        var attribute = Xrm.Page.getAttribute("AttributeName"); //Specify the name of your attribute
       var attributeValue = null;
       if (attribute != null) {
          attributeValue = attribute.getValue();
         if (attributeValue != null &&
              attributeValue != "") {
           Xrm.Utility.openEntityForm("EntityName", attributeValue);
           attribute.setValue(null);
           attribute.setSubmitMode("always");
           Xrm.Page.data.entity.save();
        }
       }
     }
   }


That’s it!

Hope, this helps. Thanks.


Thursday 10 July 2014

Convert QueryExpression to FetchXML and FetchXML to QueryExpression in MSCRM

It might a very common requirement that sometimes you need to convert FetchXMl to QueryExpression and Vice-Versa. Today i am going to share the same with all of you.

Query Expression to Fetch XML :

QueryExpression query = new QueryExpression(); 
            query.EntityName = "contact";
            query.ColumnSet = new ColumnSet(true);

            ConditionExpression cond = new ConditionExpression();
            cond.AttributeName = "firstname";
            cond.Operator = ConditionOperator.Equal;
            cond.Values.Add("Varun Singh");


            // Create Request
            QueryExpressionToFetchXmlRequest Queryexp_to_Fetch_req = new QueryExpressionToFetchXmlRequest();

            Queryexp_to_Fetch_req.Query = query;

            //Get Response
            QueryExpressionToFetchXmlResponse Queryexp_to_Fetch_resp = (QueryExpressionToFetchXmlResponse)service.Execute(Queryexp_to_Fetch_req);

            //work with newly formed fetch string
            string myfetch = Queryexp_to_Fetch_resp.FetchXml;


Fetch XML to Query Expression :


FetchXmlToQueryExpressionRequest fetch_to_QueryExp_req = new FetchXmlToQueryExpressionRequest();

            fetch_to_QueryExp_req.FetchXml = myfetch;

            FetchXmlToQueryExpressionResponse fetch_to_QueryExp_resp = (FetchXmlToQueryExpressionResponse)service.Execute(fetch_to_QueryExp_req);

            QueryExpression myquery = fetch_to_QueryExp_resp.Query;




Hope it will help someone........



















Wednesday 25 June 2014

How to Create Log File in MSCRM using c#

Sometimes you might have the requirement to create log file while writing code either in Plugin or Custom Workflow or in web service etc to trace and keep the generated error.There might be a other option as well to keep it but here i am going to show Error Log in Text file.

In this blog I have described how to create log file in C#. Log file can be simple text fileXML document or we can also use tables in database to create log. Here I have used.txt file. In this file we have stored information about generated exception of application. Using this log file we have easily find out error list. In this file we have stored information according our requirement. For example in log file we have stored file nameexception namedate and timeerror line numberevent name, Controls name etc.

Now let’s to implementation

using System;
using System.IO;
using context = System.Web.HttpContext;

namespace LogText
{
    public class Logger
    {

        public Logger(string ErrorCode, string ErrorMsg)
        {
            try
            {

                string path = context.Current.Server.MapPath("~/ErrorLogging/");
                // check if directory exists
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                path = path + DateTime.Today.ToString("dd-MMM-yy") + ".log";
                // check if file exist
                if (!File.Exists(path))
                {
                    File.Create(path).Dispose();
                }
                // log the error now
                using (StreamWriter writer = File.AppendText(path))
                {
                    string error = "\r\nLog written at        : " + DateTime.Now.ToString() +
                    "\r\n\r\nError occured on page : " + context.Current.Request.Url.ToString() +
                    "\r\n\r\nError Code            : " + ErrorCode +
                    "\r\n\r\nError Message         : " + ErrorMsg;
                    writer.WriteLine(error);
                    writer.WriteLine("=======================================");
                    writer.Flush();
                    writer.Close();
                }

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
    }
}


Where i would see the Error Log Text file ?

A folder will be created inside your Project/Solution named 'ErrorLogging'. All error log test file will be created inside this Folder with named as 'Log Creation Date.log' for example- '04-Jul-13.log'.
















Error Log File will look like as below:





Monday 23 June 2014

XML Parser to get List of All Elements, Attribute Name & Attribute Value

Function to Get Element List of XML :

 public List<string> getElements(string xmlfile)
        {

            List<string> ElementList = new List<string>();

            XmlReader reader = XmlReader.Create(new StringReader(xmlfile));
            while (reader.Read())
            {
                if (reader.NodeType.Equals(XmlNodeType.Element))
                {
                    ElementList.Add(reader.Name);
                }

            }
            return ElementList;
        }

Function to Get List of Attribute Name XML :

 public List<String> getAttributeName(string xmlfile)
        {
            List<string> AttributeNameList = new List<string>();

            XmlReader reader = XmlReader.Create(new StringReader(xmlfile));
            while (reader.Read())
            {
                if (reader.NodeType.Equals(XmlNodeType.Element))
                {

                    if (reader.HasAttributes)
                    {
                        for (int attInd = 0; attInd < reader.AttributeCount; attInd++)
                        {
                            reader.MoveToAttribute(attInd);

                            AttributeNameList.Add(reader.Name);
                        }
                    }
                }

            }
            return AttributeNameList;
        }


Function to Get List of Attribute Value XML :

 public List<String> getAttributeValue(string xmlfile)
        {
            List<string> AttributeValueList = new List<string>();

            XmlReader reader = XmlReader.Create(new StringReader(xmlfile));
            while (reader.Read())
            {
                if (reader.NodeType.Equals(XmlNodeType.Element))
                {

                    if (reader.HasAttributes)
                    {
                        for (int attInd = 0; attInd < reader.AttributeCount; attInd++)
                        {
                            reader.MoveToAttribute(attInd);
                            AttributeValueList.Add(reader.Value);
                        }
                    }
                }

            }
            return AttributeValueList;

        }













Wednesday 4 June 2014

Entity Logical Name and Entity Schema Name in MSCRM 2011

When we create an Entity, What is the difference between Entity Schema Name and Entity Logical Name ?



When we are creating an entity, at that time, the Name we give is its schema name. When we save this entity the schema name also becomes the logical name. So entities have two names; logical name and schema name. The values are same but with one difference, the casing.
For example, if I create an entity with the Name “new_TestField”. Here “new_” is the customization prefix set to maintain uniqueness in naming of components. When I save this entity, the name new_TestField will be set as schema name and “new_testfield” will be set as logical name.



As we see, the entity schema name = entity logical name. The difference is schema name retains the casing but logical name will always be lowercase. In other words we can say logical name is lower case conversion of the schema name. The same goes for attributes and relationships for an entity.

Where do we use the schema Name and when do we use the 

Logical Name of an Entity ?


  • In CRM 2011 Early bound programming model, we always use schema names.We also use schema names in “Rest/o Data” programming. 
  • Logical names are used in CRM 2011 Late bound programming model. In CRM 2011 JavaScript web resources, we use logical names.


So in this blog we saw that schema names and logical names are same except the casing but they have different usage. In plugins and custom workflow activities, if we use early bound programming model, then we have to use schema names. In plugins and custom workflow activities, if we use late bound programming model, then we have to use logical names.
I hope this blog about ‘Microsoft Dynamics CRM 2011 – Entity Logical Name and Entity Schema Name’ was informative. 

Please feel free to leave your comments.
Blogger Widgets