Pages

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 ;

       }
}

}