Translate

Sunday 25 December 2016

Generate CRM organization service using service proxy

How to generate CRM organization service using service proxy ?

Hello CRM Developers,
          This is my new post to generate organization service in CRM 2013,2015 and 2016. Simplest method to generate dynamics CRM organization service,you can use below code for creting crm organisation service. For this you need to follow below instructions.

For generation organization service below assemblies are required.
  1. Microsoft.Xrm.Sdk.dll
  2. Microsoft.Crm.Sdk.Proxy.dll
  3. System.configuration
  4. System.ServiceModel
And below name spaces will be required
  1. using Microsoft.Crm.Sdk.Messages;
  2. using Microsoft.Xrm.Sdk;
  3. using Microsoft.Xrm.Sdk.Client;
  4. using System.ServiceModel.Description;

 Add below code in .cs file and App config file respectively. 

//.CS File Code

public static IOrganizationService GetCRMService()
{
   try
   {
      // Get Ogranization Service Url
      Uri oUri = new Uri(System.Configuration.ConfigurationManager.AppSettings["OrganizationUrl"]);
      //Your credentials
      ClientCredentials clientCredentials = new ClientCredentials();
      clientCredentials.UserName.UserName = System.Configuration.ConfigurationManager.AppSettings["Username"];
      clientCredentials.UserName.Password = System.Configuration.ConfigurationManager.AppSettings["Password"];

      //Create your Organization Service Proxy
      OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(
         oUri,
         null,
         clientCredentials,
         null);
      _serviceProxy.EnableProxyTypes();

      IOrganizationService service = _serviceProxy;

      // Obtain information about the logged on user from the web service.
      Guid userId =  ((WhoAmIResponse)_serviceProxy.Execute(new WhoAmIRequest())).UserId;
      if (userId != null) 
       { return service; }
      else
       { return null; }
       }
   catch (Exception)
    {
        return null;
    }
}

//App config file code

<?xml version="1.0" encoding="utf-8"?>
<configuration>
   <appSettings>
    <!--Organization Service Endpoint Address-->
    <add key="OrganizationUrl" value="https://your organisation/XRMServices/2011/Organization.svc" />

    <!--UserName with domain-->   
    <add key="Username" value="username" />

    <!--password-->  
    <add key="Password" value="password" />
  </appSettings>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Xrm.Sdk" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
      </dependentAssembly>      
    </assemblyBinding>
  </runtime>
</configuration>
 

Enjoy the great technology Dynamics CRM. Good luck.....!!!!! 
Please feel free to put comments for your queries.Thanks.

Friday 9 December 2016

Generate Organization service using Microsoft.Xrm.Client dll

How to generate organization service using Microsoft.Xrm.Client dll ?

Hello CRM Developers,
          This is my new post to generate organization service in CRM 2013,2015 and 2016. Simplest method to generate organization service, for this only two line of C# code will be required.

For generation organization service below assemblies are required.
  1. Microsoft.Xrm.Sdk.dll
  2. Microsoft.Xrm.Client.dll
  3. System.configuration
And below name spaces will be required
  1. using Microsoft.Xrm.Client;
  2. using Microsoft.Xrm.Client.Services;
  3. using Microsoft.Xrm.Sdk;
  4. using Microsoft.Xrm.Sdk.Client;
  5. using Microsoft.Xrm.Sdk.Query;

 Add below code in .cs file and App config file respectively. 

//.CS File Code

public IOrganizationService getOrganizationService(string key)
{
    CrmConnection con = new CrmConnection("CRMOnline");
    IOrganizationService service = new OrganizationService(con);
    OrganizationServiceContext Context = new OrganizationServiceContext(service);
    return service;
}

//App config file code

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version = "v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <connectionStrings>   
    <add name = "CRMOnline" connectionString="Url=https://Your Organization URL/XRMServices/2011/Organization.svc; Username=xyz; Password=xyzpassword;"/>
  </connectionStrings>

</configuration>
 

Enjoy the great technology Dynamics CRM. Good luck.....!!!!! 
Please feel free to put comments for your queries.Thanks.

Sunday 18 September 2016

Add a button on CRM 2016 form.

How to add a button in CRM 2015/2016 form ?

Hello CRM Developers,
          This is my new post to add a new button in CRM 2015/2016.

I can understand the CRM developers requirements, because after release of CRM roll up 12 and CRM 2013, we can access CRM on cross browsers also. when we did customization with java script functionality, It may vary browser to browser, so there may be need of yours to add a custom button in CRM 2013. So here is the simple java script code for CRM 2015/2016 and it will work in CRM 2011(rollup 12) as well as in CRM 2015/2016.

Step 1:- Add a attribute of type single line text on crm 2016 form. Or you may use existing one.

Step 2:- Add the fallowing code to your crm java script web resource. And call this function on page load.
     
function createButton(atrname) {
       
        if ( window.parent.document.getElementById(atrname ) != null) {
        var fieldId = "field" + atrname ;
        if ( window.parent.document.getElementById(fieldId ) == null) {
            var elementId = window.parent.document.getElementById(atrname + "_d");
            var div = document.createElement("div");
            div.style.width = "100px";
            div.style.textAlign = "right";
            div.style.display = "inline";


            childDiv = elementId.getElementsByTagName('div')[0]
            childDiv.style.display = "none";

            elementId .appendChild(div, elementId );
            div.innerHTML = '<button id="' + fieldId + '"  type="button" style="margin-left: 3px; width: 100%;" >Click Me !!</button>';
            window.parent.document.getElementById(atrname).style.width = "0%";
            window.parent.document.getElementById(fieldId ).onclick = function () { YourOnClickFunction(); };
        }
    }
}
 

Thursday 4 August 2016

How to get data from HTML web resource components to CRM 2016 form

How to get data from HTML web resource components to CRM 2016 form.

Hello CRM Developers,
     Here is my new post, In this post I am going to tell how we can get data from html web resource to crm 2016 form events.

 On CRM 2016 from if there is a html web resource  placed in iframe and suppose you have text boxes and check boxes on html page and you want data from text boxes and check boxes on crm form events like on save or on field change events, we can get this data by using below java script code.

Below is a sample code in it we are reading data from check boxes on html page and after reading we can save that data on save event of crm 2016 form.




function readDataFromHTMLPage() {

    //Get web resource control
    var webResCrtl = Xrm.Page.ui.controls.get("WebResource_TestWebPage");
    if (webResCrtl) {
        //get web resource object
        var webResObject = webResCrtl.getObject();
        if (webResObject) {
            //Get HTML document
            var htmlDocument = webResObject.contentWindow.document;
            if (htmlDocument) {
                //Get all check boxes with class name "items"
                var checkBoxes = htmlDocument.getElementsByClassName("items")
                var selectedIntractionCheckBoxes = "";
                for (var i = 0; i < checkBoxes.length; i++) {
                    //Get Selected check boxes
                    if (checkBoxes[i].childNodes['0'].checked == true) {
                        if (selectedIntractionCheckBoxes == "")
                            //write your logic to perform action
                            selectedIntractionCheckBoxes = checkBoxes[i].textContent;
                       
                    }
                }                
            }
        }
    }
}



For further help you can leave a comment.

Enjoy the great technology Dynamics CRM. Good Luck .....!!!! Please feel free to leave comment.
Thanks

Tuesday 2 August 2016

How to import CRM 2016 solution to CRM 2015, Import solution from higher CRM to lower CRM version

How to import CRM 2016 solution to CRM 2015, Import solution from higher CRM to lower CRM version.

Hello CRM Developers,
     Here is my new post, In this post I am going to to tell how we can import crm solution from higher to lower version, Obviously it is not recommended nor we required most of time, we rarely required but we do not know when could we in such a situation or we got a requirement ?

There are some set of instructions by which we can import solution from higher to lower version.
I am taking an example for importing CRM 2016 solution to CRM 2015.

Below are step by step instructions for importing CRM solution from higher CRM version to lower CRM version.

Step 1:- Export solution from higher CRM version.

Step 2:- Open "solution" xml file in any xml editor and find below text.

  • version
  • SolutionPackageVersion
  • behavior
Step 3:- Now change values for version and SolutionPackageVersion and remove behavior="0", like below.

Exported CRM solution file before change

<ImportExportXml version="8.0.0001.0079" SolutionPackageVersion="8.0" languagecode="1033" generatedBy="CrmLive" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <SolutionManifest>
    <UniqueName>Test</UniqueName>
    <LocalizedNames>
      <LocalizedName description="Test" languagecode="1033" />
    </LocalizedNames>
    <Descriptions />
    <Version>1.0</Version>
    <Managed>0</Managed>
    <Publisher>
      <UniqueName>DefaultPublishermyninja</UniqueName>
      <LocalizedNames>
        <LocalizedName description="Default Publisher for myninja" languagecode="1033" />
      </LocalizedNames>
      <Descriptions>
        <Description description="Default publisher for this organization" languagecode="1033" />
      </Descriptions>
      <EMailAddress xsi:nil="true"></EMailAddress>
      <SupportingWebsiteUrl xsi:nil="true"></SupportingWebsiteUrl>
      <CustomizationPrefix>new</CustomizationPrefix>
      <CustomizationOptionValuePrefix>10000</CustomizationOptionValuePrefix>
      <Addresses>
        <Address>
          <AddressNumber>1</AddressNumber>
          <AddressTypeCode xsi:nil="true"></AddressTypeCode>
          <City xsi:nil="true"></City>
          <County xsi:nil="true"></County>
          <Country xsi:nil="true"></Country>
          <Fax xsi:nil="true"></Fax>
          <FreightTermsCode xsi:nil="true"></FreightTermsCode>
          <ImportSequenceNumber xsi:nil="true"></ImportSequenceNumber>
          <Latitude xsi:nil="true"></Latitude>
          <Line1 xsi:nil="true"></Line1>
          <Line2 xsi:nil="true"></Line2>
          <Line3 xsi:nil="true"></Line3>
          <Longitude xsi:nil="true"></Longitude>
          <Name xsi:nil="true"></Name>
          <PostalCode xsi:nil="true"></PostalCode>
          <PostOfficeBox xsi:nil="true"></PostOfficeBox>
          <PrimaryContactName xsi:nil="true"></PrimaryContactName>
          <ShippingMethodCode xsi:nil="true"></ShippingMethodCode>
          <StateOrProvince xsi:nil="true"></StateOrProvince>
          <Telephone1 xsi:nil="true"></Telephone1>
          <Telephone2 xsi:nil="true"></Telephone2>
          <Telephone3 xsi:nil="true"></Telephone3>
          <TimeZoneRuleVersionNumber xsi:nil="true"></TimeZoneRuleVersionNumber>
          <UPSZone xsi:nil="true"></UPSZone>
          <UTCOffset xsi:nil="true"></UTCOffset>
          <UTCConversionTimeZoneCode xsi:nil="true"></UTCConversionTimeZoneCode>
        </Address>        
      </Addresses>
    </Publisher>
    <RootComponents>
      <RootComponent type="60" id="{028e1263-abec-4b11-8958-984195c8d2b3}" behavior="0" />
      <RootComponent type="60" id="{66c79877-1d08-4a33-8871-e5a95d666ff6}" behavior="0" />
      <RootComponent type="60" id="{814617a5-03aa-40c1-a6bf-c7c1176f4e65}" behavior="0" />
      <RootComponent type="91" schemaName="TestPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=928f120268c8daa4" behavior="0" />
    </RootComponents>
    <MissingDependencies>
      <MissingDependency>
        <Required key="4" type="1" schemaName="new_scans" displayName="Scans" solution="Active" />
        <Dependent key="5" type="60" displayName="Information" parentDisplayName="Scans" id="{814617a5-03aa-40c1-a6bf-c7c1176f4e65}" />
      </MissingDependency>
      </MissingDependencies>
  </SolutionManifest>
</ImportExportXml>


CRM solution file after change - version and SolutionPackageVersion changed from 8.0 to 7.0 and behavior="0" has removed.



<ImportExportXml version="7.0.0001.0079" SolutionPackageVersion="7.0" languagecode="1033" generatedBy="CrmLive" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <SolutionManifest>
    <UniqueName>Test</UniqueName>
    <LocalizedNames>
      <LocalizedName description="Test" languagecode="1033" />
    </LocalizedNames>
    <Descriptions />
    <Version>1.0</Version>
    <Managed>0</Managed>
    <Publisher>
      <UniqueName>DefaultPublishermyninja</UniqueName>
      <LocalizedNames>
        <LocalizedName description="Default Publisher for myninja" languagecode="1033" />
      </LocalizedNames>
      <Descriptions>
        <Description description="Default publisher for this organization" languagecode="1033" />
      </Descriptions>
      <EMailAddress xsi:nil="true"></EMailAddress>
      <SupportingWebsiteUrl xsi:nil="true"></SupportingWebsiteUrl>
      <CustomizationPrefix>new</CustomizationPrefix>
      <CustomizationOptionValuePrefix>10000</CustomizationOptionValuePrefix>
      <Addresses>
        <Address>
          <AddressNumber>1</AddressNumber>
          <AddressTypeCode xsi:nil="true"></AddressTypeCode>
          <City xsi:nil="true"></City>
          <County xsi:nil="true"></County>
          <Country xsi:nil="true"></Country>
          <Fax xsi:nil="true"></Fax>
          <FreightTermsCode xsi:nil="true"></FreightTermsCode>
          <ImportSequenceNumber xsi:nil="true"></ImportSequenceNumber>
          <Latitude xsi:nil="true"></Latitude>
          <Line1 xsi:nil="true"></Line1>
          <Line2 xsi:nil="true"></Line2>
          <Line3 xsi:nil="true"></Line3>
          <Longitude xsi:nil="true"></Longitude>
          <Name xsi:nil="true"></Name>
          <PostalCode xsi:nil="true"></PostalCode>
          <PostOfficeBox xsi:nil="true"></PostOfficeBox>
          <PrimaryContactName xsi:nil="true"></PrimaryContactName>
          <ShippingMethodCode xsi:nil="true"></ShippingMethodCode>
          <StateOrProvince xsi:nil="true"></StateOrProvince>
          <Telephone1 xsi:nil="true"></Telephone1>
          <Telephone2 xsi:nil="true"></Telephone2>
          <Telephone3 xsi:nil="true"></Telephone3>
          <TimeZoneRuleVersionNumber xsi:nil="true"></TimeZoneRuleVersionNumber>
          <UPSZone xsi:nil="true"></UPSZone>
          <UTCOffset xsi:nil="true"></UTCOffset>
          <UTCConversionTimeZoneCode xsi:nil="true"></UTCConversionTimeZoneCode>
        </Address>        
      </Addresses>
    </Publisher>
    <RootComponents>
      <RootComponent type="60" id="{028e1263-abec-4b11-8958-984195c8d2b3}" behavior="0" />
      <RootComponent type="60" id="{66c79877-1d08-4a33-8871-e5a95d666ff6}" behavior="0" />
      <RootComponent type="60" id="{814617a5-03aa-40c1-a6bf-c7c1176f4e65}" behavior="0" />
      <RootComponent type="91" schemaName="TestPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=928f120268c8daa4" />
    </RootComponents>
    <MissingDependencies>
      <MissingDependency>
        <Required key="4" type="1" schemaName="new_scans" displayName="Scans" solution="Active" />
        <Dependent key="5" type="60" displayName="Information" parentDisplayName="Scans" id="{814617a5-03aa-40c1-a6bf-c7c1176f4e65}" />
      </MissingDependency>
      </MissingDependencies>
  </SolutionManifest>
</ImportExportXml>

Step 3:- Now save solution.xml file and compress using only windows compression not with any other compress tool and then import solution to version 7.0 (CRM 2015), I am sure it will be imported successfully.


Note:- this is not supported way and not recommended by Microsoft. Most of time it works but it may not work properly, it also depends on your crm customization. If your crm solution contains minimal customization then chances are higher to work properly.


For further help you can leave a comment.

Enjoy the great technology Dynamics CRM. Good Luck .....!!!! Please feel free to leave comment.
Thanks

Monday 1 August 2016

Update record in crm 2016 using crm web api with java script

Retrieve record in CRM 2016 using CRM web API with java script.

Hello CRM Developers,
          Here is my new post, In this post I am going to to tell how to update record in dynamics CRM 2016 using CRM web API.

In new CRM 2016 release there is a new way introduced for operation like create, update, delete,retrieve, multiple retrieve etc, web API. Web API has been introduced so that communication between CRM and and other platform application can be done easily. New CRM web API is fully supports JSON format.

Below is the sample java script code for retrieving record in CRM using java script.

function update() {
    var clientURL = Xrm.Page.context.getClientUrl();
    var req = new XMLHttpRequest()
    var query = "/api/data/v8.0/accounts(5AC84B7C-4D57-E611-80DC-705A0F235AE3)";
    req.open("PATCH", encodeURI(clientURL + query), true);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.onreadystatechange = function () {
        if (this.readyState == 4) {
            req.onreadystatechange = null;
            if (this.status == 204) {
                alert("Success");
            }
            else {
                var error = JSON.parse(this.response).error;
                alert("Error deleting Account – " + error.message);
            }
        }
    };

    //Create object of entity
    var account = new Object();
    //String Field
    account.name = "Test Neo";
    //Option Set field
    account.ownershipcode = 1;
    //Two option
    account.donotemail = true;
    //Currency
    account.creditlimit = 12345;
    //Whole number
    account.numberofemployees = 28;
    //Lookup
    account["primarycontactid@odata.bind"] = "/contacts(7166DE85-1858-E611-80DD-705A0F235AE3)"

    req.send(JSON.stringify(account));
}

For further help you can leave a comment.

Enjoy the great technology Dynamics CRM. Good Luck .....!!!!
Thanks

Sunday 31 July 2016

Delete record in CRM 2016 using crm web api with java script

Retrieve record in CRM 2016 using CRM web API with java script.

Hello CRM Developers,
          Here is my new post, In this post I am going to to tell how to delete record in dynamics CRM 2016 using CRM web API.

In new CRM 2016 release there is a new way introduced for operation like create, update, delete,retrieve, multiple retrieve etc, using web API. Web API has been introduced so that communication between CRM and and other platform application can be done easily. New CRM web API is fully supports JSON format.

Below is the sample java script code for retrieving record in CRM using java script.


function deleteRecord() {    
    var clientURL = Xrm.Page.context.getClientUrl();
    var req = new XMLHttpRequest()
    var query = "/api/data/v8.0/accounts(00000000-0000-0000-0000-000000000000)";
    req.open("Delete", encodeURI(clientURL + query), true);   
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.onreadystatechange = function () {
        if (this.readyState == 4) {
            req.onreadystatechange = null;
            if (this.status == 204) {
                alert("Success");
            }
            else {
                var error = JSON.parse(this.response).error;
                alert("Error deleting Account – " + error.message);
            }
        }
    };
    req.send(null);
}


For further help you can leave a comment.

Enjoy the great technology Dynamics CRM. Good Luck .....!!!!
Thanks