Pages

Thursday 15 November 2012

Calcluating sub grid items on close of child crm2011 form

If you want to update field of parent form based on the subgrid item without refreshing or save parent form
you can follow these steps .

1. Attach close event  to the load event of child form
function on_childform()
{
 window.attachEvent ("onunload", ParentFormFieldUpdate);
}
2. Retrieve gird elements by  SOAP  method (this  i will explain on my next blog)

3. Perform action on the ParentFormFieldUpdate()
.function ParentFormFieldUpdate()
{
//Retreieve by soap Method .
//perform action on the retrieved data  //put condition regarding of parent enitty id.
//then  updated parent from field by

window.parent.opener.Xrm.Page.getAttribute("linu_totalaveragegrossdiscount").setValue(totalgrossdiscount);


}

This will update parent form field by closing child form .

You can easly avoid unwanted button on CRM form.



Sunday 1 July 2012

Find Time Difference of two DateTime filed in CRM2011 Javascript


function onchange_endate()
{
var startday = Xrm.Page.getAttribute("linu_plannedstartdate").getValue();
 var endday = Xrm.Page.getAttribute("linu_plannedenddate").getValue();


if( startday !=null  && endday !=null)
{

var time2= endday.getTime();
var time1=startday.getTime();
 var time3= time2-time1;

var hoursDifference = (time3/1000/60/60);
var  temptime  =Math.round(hoursDifference );
if(temptime >hoursDifference )
{
hoursDifference =hoursDifference -0.20;

}

//here  linu_plannedestimatedtime is floating point number to save result timediffernce.
    Xrm.Page.getAttribute("linu_plannedestimatedtime").setValue(hoursDifference);
}
}

Sunday 24 June 2012

Pass Array to Functions in Silveright Enabled WCF

1. Go to Silverlight project .

2.Right click and select 'Add Service Reference'


3.Type Service URL and Click on 'Discover'
4.Click on Advanced

5.Select  System Array from drop Down list .


Thursday 7 June 2012

CRM 2011 Outlook Client "The server address (URL) is not valid.

Solution
1. Make a host entry  for CRM server  in Client System.

Solution 2
1.Check server address and Port number are correct

Create Depended Optionset in CRM2011


1. Convert the desired filtering of options into the following XML document and upload it as an XML Web resource .

For Example :<DependentOptionSetConfig entity="incident" >
 <ParentField id="linu_category"
              label="Category">
  <DependentField id="linu_subcategory"
                  label="Sub Category" />
  <Option value="220100000"
          label="Created">
     <ShowOption value="220100001"
               label="ID Number notified" />
     </Option>
  <Option value="220100001"
          label="ID Number notified">
     <ShowOption value="220100002"
               label="Assigned to Department Manager" />
    </Option>
 </ParentField>
</DependentOptionSetConfig>

2.Create a JScript Web resource using the following code.

if (typeof (SDK) == "undefined")
{ SDK = {}; }
// Create a Namespace container for functions in this library;
SDK.DependentOptionSet = {
 init: function (webResourceName) {
  //Retrieve the XML Web Resource specified by the parameter passed.
  var configWR = new ActiveXObject("Msxml2.DOMDocument.6.0");
  configWR.async = false;
  var serverURL = Xrm.Page.context.getServerUrl();
  if (serverURL.match(/\/$/)) {
   serverURL = serverURL.substring(0, serverURL.length - 1);
  }
  var pathToWR = serverURL + "/WebResources/" + webResourceName;
  configWR.load(pathToWR);

  //Convert the XML Data into a JScript object.
  var ParentFields = configWR.selectNodes("//ParentField");
  var JSConfig = [];
  for (var i = 0; i < ParentFields.length; i++) {
   var node = ParentFields[i];
   var mapping = {};
   mapping.parent = node.getAttribute("id");
   mapping.dependent = node.selectSingleNode("DependentField").getAttribute("id");
   mapping.options = [];
   var options = node.selectNodes("Option");
   for (var a = 0; a < options.length; a++) {
    var option = {};
    option.value = options[a].getAttribute("value");
    option.showOptions = [];
    var optionsToShow = options[a].selectNodes("ShowOption");
    for (var b = 0; b < optionsToShow.length; b++) {
     var optionToShow = {};
     optionToShow.value = optionsToShow[b].getAttribute("value");
     optionToShow.text = optionsToShow[b].getAttribute("label"); // Label is not used in the code.

     option.showOptions.push(optionToShow);
    }
    mapping.options.push(option);
   }
   JSConfig.push(mapping);
  }
  // Attach the configuration object to DependentOptionSet
  // so it will be available for the OnChange events.
  SDK.DependentOptionSet.config = JSConfig;

  //Fire the OnChange event for the mapped optionset fields
  // so that the dependent fields are filtered for the current values.
  for (var depOptionSet in SDK.DependentOptionSet.config) {
   var parent = SDK.DependentOptionSet.config[depOptionSet].parent;
   Xrm.Page.data.entity.attributes.get(parent).fireOnChange();
  }

 },

 // This is the function set on the OnChange event for
 // parent fields.
 filterDependentField: function (parentField, childField) {
  for (var depOptionSet in SDK.DependentOptionSet.config) {
   var DependentOptionSet = SDK.DependentOptionSet.config[depOptionSet];
   /* Match the parameters to the correct dependent optionset mapping*/
   if ((DependentOptionSet.parent == parentField) && (DependentOptionSet.dependent == childField)) {
    /* Get references to the related fields*/
    var ParentField = Xrm.Page.data.entity.attributes.get(parentField);
    var ChildField = Xrm.Page.data.entity.attributes.get(childField);
    /* Capture the current value of the child field*/
    var CurrentChildFieldValue = ChildField.getValue();

    /* If the parent field is null the Child field can be set to null */
    if (ParentField.getValue() == null) {
     ChildField.setValue(null);
     ChildField.setSubmitMode("always");
     ChildField.fireOnChange();

     // Any attribute may have any number of controls,
     // so disable each instance.
     var controls = ChildField.controls.get()

     for (var ctrl in controls) {
      controls[ctrl].setDisabled(true);
     }
     return;
    }

    for (var os in DependentOptionSet.options) {
     var Options = DependentOptionSet.options[os];
     var optionsToShow = Options.showOptions;
     /* Find the Options that corresponds to the value of the parent field. */
     if (ParentField.getValue() == Options.value) {
      var controls = ChildField.controls.get();
      /*Enable the field and set the options*/
      for (var ctrl in controls) {
       controls[ctrl].setDisabled(false);
       controls[ctrl].clearOptions();

       for (var option in optionsToShow) {
        controls[ctrl].addOption(optionsToShow[option]);
       }

      }
      /*Check whether the current value is valid*/
      var bCurrentValueIsValid = false;
      var ChildFieldOptions = optionsToShow;

      for (var validOptionIndex in ChildFieldOptions) {
       var OptionDataValue = ChildFieldOptions[validOptionIndex].value;

       if (CurrentChildFieldValue == OptionDataValue) {
        bCurrentValueIsValid = true;
        break;
       }
      }
      /*
      If the value is valid, set it.
      If not, set the child field to null
      */
      if (bCurrentValueIsValid) {
       ChildField.setValue(CurrentChildFieldValue);
      }
      else {
       ChildField.setValue(null);
      }
      ChildField.setSubmitMode("always");
      ChildField.fireOnChange();
      break;
     }
    }
   }
  }
 }
};

3.Add the linu_SDK.DependentOptionSetSample.js Script Web resource to the JScript libraries available for the form.

4.In the Onload event for the form, configure the event handler to call the SDK.DependentOptionSet.init function and pass in the name of the XML Web resource as a parameter.

5.In the OnChange event for the Category field, set the Function to SDK.DependentOptionSet.filterDependentField.

6.In the Comma separated list of parameters that will be passed to the function text box enter: "linu_category", "linu_subcategory".


7.Save and publish all customizations.


Convert Entity Type to XRM Contact type in CRM2011




namespace ConvertEntity
{
    public class ConatactAccess: PortalClass
    {
        public IEnumerable<Entity> CurrentUsercontact
        {
            get
            {
                var emptyResult = new List<Entity>();

                return GetLoginContact(ServiceContext, "Admin");

            }
        }

        public IEnumerable<Entity> GetLoginContact(OrganizationServiceContext context, string username)
        {
            var result = new List<Entity>();

            var findContact =
                from c in context.CreateQuery("contact")
                where c.GetAttributeValue<string>("linu_username") == username
                select c;

            result.AddRange(findContact);

                return result;
        }

       public  Contact retunruser()
       {
           var contactresult = new ConatactAccess().CurrentUsercontact.Cast<Contact>();

           Contact contactre = null;

           foreach (Contact item in contactresult)
           {
               contactre = item;
           }

           return contactre ;

       }
}

}

Wednesday 23 May 2012

Outlook 2010 Ribbon Disappear After CRM Client Installation

1.Exit Outlook.
2.Click Start, click Run, type regedit, and then click OK.
3.Locate the following registry subkey:
4.HKEY_CLASSES_ROOT\TypeLib\{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}
5.Right-click the 2.4 registry key, and then select Export. Save the export to your desktop to create a backup.
6.Right-click the 2.4 key again, and then select delete.
7.Start Outlook.

Java Script Set Focus on CRM Form Tab


Suppose contacts is tab name on Account Enitity.
var  Tabobj  =Xrm.Page.ui.tabs.get(“contacts”);
Tabobj  .setFocus();