Thursday, January 22, 2015

Disable HTML web resource control from CRM Form events

Call below function on CRM form event to access HTML web resource control by tag or Id



function DisableHTMLWebresouceControl()
{
//Get HTML web resource control
 var webRefCtrl = Xrm.Page.getControl('Your web resource ID from form').getObject();

 //web resource HTML document
 var htmlDoc=webRefCtrl.contentDocument;

 //get list of controls by tag name
 var ctrlList = htmlDoc.getElementsByTagName('select');

 //get list of controls by Id
 var ctrlById= doc.getElementById('textCtrl');

 //If web resource is not loaded yet, then call same function after some time.
  if(ctrlList[0]==null)
  {
     setTimeout(DisableHTMLWebresouceControl,1000)
     return;
  }
 
 // disable control in HTML web resource.
 ctrlList[0].disabled =true;
}


Wednesday, January 21, 2015

View Sorting more than two columns

In CRM when creating view, CRM UI is allowing to sort view by only two columns.



User can sort views by multiple columns when it views opens and by using [SHIFT + click] on multiple columns.



 When we want to sort view by multiple columns when it opens, then need to export customization and need to made changes in customization xml.

Step 1:  Export customization of entity whose view want to sort by more than two columns.
Step 2: Extract and open customization.xml file in Visual studio or XML editor.
Step 3: In the Customization.xml look for Savedquery section for your entity.
Step 4: Find Savedquery of view which you want to sort by more than two columns.
  Saved Query has LocalizedName tag which gives view name.  
Step 5: To sort by more column we need to modify fetchxml of saved query.
General saved query fetch xml will be like

<fetchxml>
              <fetch version="1.0" mapping="logical">
                <entity name="edm_test">
                  <attribute name="edm_name" />
                  <attribute name="createdon" />
                  <order attribute="edm_name" descending="false" />
                  <order attribute="new_age" descending="false" />
                  <filter type="and">
                    <condition attribute="statecode" operator="eq" value="0" />
                  </filter>
                  <attribute name="new_phone" />
                  <attribute name="new_email" />
                  <attribute name="new_date" />
                  <attribute name="new_age" />
                  <attribute name="edm_testid" />
                </entity>
              </fetch>
         </fetchxml>

To sort by more columns add order tag as
             


Final fetchxml will be
<fetchxml>
              <fetch version="1.0" mapping="logical">
                <entity name="edm_test">
                  <attribute name="edm_name" />
                  <attribute name="createdon" />
                  <order attribute="edm_name" descending="false" />
                  <order attribute="new_age" descending="false" />
    <order attribute="new_phone" descending="false" />
                  <filter type="and">
                    <condition attribute="statecode" operator="eq" value="0" />
                  </filter>
                  <attribute name="new_phone" />
                  <attribute name="new_email" />
                  <attribute name="new_date" />
                  <attribute name="new_age" />
                  <attribute name="edm_testid" />
                </entity>
              </fetch>
         </fetchxml>

Step 6: Save customization.xml file, import and publish. 



Tuesday, January 20, 2015

Show only Time for Date Time Attribute

In CRM you can show only Date part of date time attribute, but not only time.

To show only date part of date time attribute, you need to go field customization and change Format as Date. 


You can show only time for date time attribute either by modifying CRM entity form HTML using Javascript or by adding web resource.

Modifying CRM form HTML (DOM) is not supported, so I will go with web resource.

1.       Add HTML web resource on your form.
2.       Set HTML web resource properties like, Number of rows, scrolling border, formatting etc.
3.       Add web resource on your form, This HTML web resource should be look like attribute on Form, so set properties accordingly.
4.       Add Jquery latest library in your entity form libraries.

5.       Add Following code into you HTML web resource. 


1.       Change < script type="text/javascript" src="new_jquery_1.10.2.js" > < /script >  as per your JQuery library name.
2.       Hide your date field on form.
3.       Save and publish customization.

Here is your output