Translate

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