Translate

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

Sunday, 6 March 2016

Retrieve 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 retrieve 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. CRM Organization service is going to obsolete in this CRM by Microsoft. 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 support JSON format.

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


function retrieveRecord() {    
    var clientURL = Xrm.Page.context.getClientUrl();
    var req = new XMLHttpRequest()
    var query = "/api/data/v8.0/accounts?$select=name&$top=1";
    req.open("GET", 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 == 200) {
                var data = JSON.parse(this.response);
                if (data && data.value) {
                    for (var indxAccounts = 0; indxAccounts < data.value.length; indxAccounts++) {
                        var accountName = data.value[indxAccounts].name;
                        var eTag = data.value[indxAccounts]['@odata.etag'];
                    }
                }
            }
            else {
                var error = JSON.parse(this.response).error;
                alert("Error retrieving Accounts – " + error.message);
            }
        }
    };
    req.send(null);
}

Only query will change for different type of retrieve. Below are the different retrieve queries.

1. Retrieve top 1 record
   
var query = "/api/data/v8.0/accounts?$select=name&$top=1"
      
2. Retrieve records with lookup condition like records owned bay a user.

var query = "/api/data/v8.0/accounts? $select=name,accountnumber,_primarycontactid_value,createdon,accountcategorycode,revenue&$filter=_ownerid_value eq (212626EE-54B9-4E99-93F9-0BF5FDCA3481)"

3. Retrieve accounts whose name starts with B or C.

var query ="accounts?$filter=startswith(name,'B') or startswith(name,'C')"

4. Retrieve related entity attributes.

var query ="/api/data/v8.0/accounts(B14CC863-07E3-E511-80EE-3863BB2E4DE0)?$select=name,accountnumber,_primarycontactid_value,createdon,accountcategorycode,revenue&$orderby=name&$expand=primarycontactid($select=fullname,telephone1,email)" 

For further help you can leave a comment.

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

Saturday, 5 March 2016

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

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

Hello CRM Developers,
          Here is my new post, In this post I am going to to tell how to create 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. CRM Organization service is going to obsolete in this CRM by Microsoft. 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 support JSON format.

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



function cerateRecord(clientURL)
{  
    //clientURL = your CRM organization URL.  
    var req = new XMLHttpRequest()    
    req.open("POST", encodeURI(clientURL + "/api/data/v8.0/accounts"), 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 /* complete */) {
            req.onreadystatechange = null;
            if (this.status == 204) {
                var accountUri = this.getResponseHeader("OData-EntityId");                
            }
            else {
                var error = JSON.parse(this.response).error;
            }
        }
    };
    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(C8944807-EFD9-E511-80EC-3863BB2E4DE0)"
    var response = req.send(JSON.stringify(account));
}


For further help you can leave a comment.

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