Friday, October 14, 2016

Dynamically Create HTML Table with JQGrid FetchXML MSCRM

Hi All,

Dynamically Create HTML Table with JQGrid FetchXML MSCRM

<html>
<head>

    <title>Log Details</title>
    <style type="text/css">
        body {
            font-family: Arial;
            font-size: 10pt;
        }

        table {
            border: 1px solid #ccc;
            border-collapse: collapse;
        }

            table th {
                background-color: #F7F7F7;
                color: #333;
                font-weight: bold;
            }

            table th, table td {
                padding: 5px;
                border-color: #ccc;
            }
    </style>
    <script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
    <script src="../WebResources/Jquery.min.js" type="text/javascript"></script>
    <script src="../WebResources/bootstrap.min.js" type="text/javascript"></script>
    <script src="../WebResources/grid.locale_en.js" type="text/javascript"></script>
    <script src="../WebResources/jquery.jqgrid.min.js" type="text/javascript"></script>
    <script src="../WebResources/scripts/XrmServiceToolkit" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        function getAccountServices() {
            var getQueryString = function (field) {
                var href = decodeURIComponent(window.location.href);
                var reg = new RegExp('[?&]' + field + '=([^&#]*)', 'i');
                var string = reg.exec(href);
                return string ? string[1] : null;
            };

            var ContactID = getQueryString('contact');
            var CaseID = getQueryString('case');

            var SecurityLogFetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
  "<entity name= 'new_names'>" +
    "<attribute name='new_namesid' />" +
    "<attribute name='new_name' />" +
    "<attribute name='new_dates' />" +
    "<attribute name='new_loopstring' />" +
    "<order attribute='new_name' descending='false' />" +
    "<filter type='and'>" +
      "<filter type='and'>" +
        "<condition attribute='new_case' operator='eq' value='" + CaseID + "' />" +
        "<condition attribute='new_contact' operator='eq' value='" + ContactID + "' />" +
      "</filter>" +
    "</filter>" +
  "</entity>" +
"</fetch>";
            var contactsLog = new Array();
            contactsLog.push(["Name", "Date", "LoopString"]);
            var contactRecords = XrmServiceToolkit.Soap.Fetch(SecurityLogFetchXML);
            if (contactRecords.length > 0) {
                for (var contact = 0 ; contact < contactRecords.length; contact++) {
                    contactsLog.push([
                        contactRecords[contact].attributes.new_name? contactRecords[contact].attributes.new_name.value : "",
                        contactRecords[contact].attributes.new_dates ? contactRecords[contact].attributes.new_dates.value : "",
                        contactRecords[contact].attributes.new_loopstring ? contactRecords[contact].attributes.new_loopstring.value : "",
                    ]);
                }
                //Build an array containing Customer records.

                //Create a HTML Table element.
                var table = document.createElement("TABLE");
                table.border = "1";
                //Get the count of columns.
                var columnCount = contactsLog[0].length;
                //Add the header row.
                var row = table.insertRow(-1);
                for (var i = 0; i < columnCount; i++) {
                    var headerCell = document.createElement("TH");
                    headerCell.innerHTML = contactsLog[0][i];
                    row.appendChild(headerCell);
                }
                //Add the data rows.

                for (var i = 1; i < contactsLog.length; i++) {
                    row = table.insertRow(-1);
                    for (var j = 0; j < columnCount; j++) {
                        var cell = row.insertCell(-1);
                        cell.innerHTML = contactsLog[i][j];
                    }
                }
                var dvTable = document.getElementById("dvTable");
                dvTable.innerHTML = "";
                dvTable.appendChild(table);
            }
        }

    </script>
</head>
<body onload="getAccountServices();" style="overflow-wrap: break-word;">
    <div id="dvTable">

    </div>

</body>

Dynamically Create HTML Table with JQGrid FetchXML MSCRM

Hi All,

Dynamically Create HTML Table with JQGrid FetchXML MSCRM

<html>
<head>

    <title>Log Details</title>
    <style type="text/css">
        body {
            font-family: Arial;
            font-size: 10pt;
        }

        table {
            border: 1px solid #ccc;
            border-collapse: collapse;
        }

            table th {
                background-color: #F7F7F7;
                color: #333;
                font-weight: bold;
            }

            table th, table td {
                padding: 5px;
                border-color: #ccc;
            }
    </style>
    <script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
    <script src="../WebResources/Jquery.min.js" type="text/javascript"></script>
    <script src="../WebResources/bootstrap.min.js" type="text/javascript"></script>
    <script src="../WebResources/grid.locale_en.js" type="text/javascript"></script>
    <script src="../WebResources/jquery.jqgrid.min.js" type="text/javascript"></script>
    <script src="../WebResources/scripts/XrmServiceToolkit" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        function getAccountServices() {
            var getQueryString = function (field) {
                var href = decodeURIComponent(window.location.href);
                var reg = new RegExp('[?&]' + field + '=([^&#]*)', 'i');
                var string = reg.exec(href);
                return string ? string[1] : null;
            };

            var ContactID = getQueryString('contact');
            var CaseID = getQueryString('case');

            var SecurityLogFetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
  "<entity name= 'new_names'>" +
    "<attribute name='new_namesid' />" +
    "<attribute name='new_name' />" +
    "<attribute name='new_dates' />" +
    "<attribute name='new_loopstring' />" +
    "<order attribute='new_name' descending='false' />" +
    "<filter type='and'>" +
      "<filter type='and'>" +
        "<condition attribute='new_case' operator='eq' value='" + CaseID + "' />" +
        "<condition attribute='new_contact' operator='eq' value='" + ContactID + "' />" +
      "</filter>" +
    "</filter>" +
  "</entity>" +
"</fetch>";
            var contactsLog = new Array();
            contactsLog.push(["Name", "Date", "LoopString"]);
            var contactRecords = XrmServiceToolkit.Soap.Fetch(SecurityLogFetchXML);
            if (contactRecords.length > 0) {
                for (var contact = 0 ; contact < contactRecords.length; contact++) {
                    contactsLog.push([
                        contactRecords[contact].attributes.new_name? contactRecords[contact].attributes.new_name.value : "",
                        contactRecords[contact].attributes.new_dates ? contactRecords[contact].attributes.new_dates.value : "",
                        contactRecords[contact].attributes.new_loopstring ? contactRecords[contact].attributes.new_loopstring.value : "",
                    ]);
                }
                //Build an array containing Customer records.

                //Create a HTML Table element.
                var table = document.createElement("TABLE");
                table.border = "1";
                //Get the count of columns.
                var columnCount = contactsLog[0].length;
                //Add the header row.
                var row = table.insertRow(-1);
                for (var i = 0; i < columnCount; i++) {
                    var headerCell = document.createElement("TH");
                    headerCell.innerHTML = contactsLog[0][i];
                    row.appendChild(headerCell);
                }
                //Add the data rows.

                for (var i = 1; i < contactsLog.length; i++) {
                    row = table.insertRow(-1);
                    for (var j = 0; j < columnCount; j++) {
                        var cell = row.insertCell(-1);
                        cell.innerHTML = contactsLog[i][j];
                    }
                }
                var dvTable = document.getElementById("dvTable");
                dvTable.innerHTML = "";
                dvTable.appendChild(table);
            }
        }

    </script>
</head>
<body onload="getAccountServices();" style="overflow-wrap: break-word;">
    <div id="dvTable">

    </div>

</body>

Get Value from Query String HTML/JavaScript

Hi All,

Code below for Getting HTML/Javascript Value from QueryString


            var getQueryString = function (field) {
                var href = decodeURIComponent(window.location.href);
                var reg = new RegExp('[?&]' + field + '=([^&#]*)', 'i');
                var string = reg.exec(href);
                return string ? string[1] : null;
            };

var ContactID = getQueryString('contact');

Xrm.Utility.openWebResource Parameters with Height and Width

Hi All,


Code for Passing Parameter to WebResource CRM

var customParameters = encodeURIComponent("&Parameter1=" + Param1+ "&Parameter2=" + Param2);

Xrm.Utility.openWebResource("new_Grid", customParameters, 848, 275);

Convert Long to date C#

Hi All,

Code for getting Date from string

string loopListValue = "19900131000000";

DateTime GetDate= Number2Date(Convert.ToInt64(loopListValue));

private DateTime Number2Date(long number)
        {
            string strNum = number.ToString();
            int day, month, year;
            DateTime validDate = DateTime.Now;
            if (strNum.Length == 7)
            {
                strNum = "0" + strNum;
            }

            year = Convert.ToInt32(strNum.Substring(0, 4));
            month = Convert.ToInt32(strNum.Substring(4, 2));
            day = Convert.ToInt32(strNum.Substring(6, 2));
            validDate = new DateTime(year, month, day);
            return validDate;
        }

Monday, October 10, 2016

Get Hours/Seconds from DateTime MSCRM Javascript

Hi All,

Please find the below Code to get the Hours/Seconds difference from DateTime using Javascript


function Onload()
{
var d2 = new Date(),    // Pass 2nd Date Time
 dformat = [d2.getMonth() + 1,
               d2.getDate(),
               d2.getFullYear()].join('-') + ' ' +
              [d2.getHours(),
               d2.getMinutes(),
               d2.getSeconds()].join(':');
        var d1 = new Date(), // Pass 1st Date Time
 dformat = [d1.getMonth() + 1,
               d1.getDate(),
               d1.getFullYear()].join('-') + ' ' +
              [d1.getHours(),
               d1.getMinutes(),
               d1.getSeconds()].join(':');
        var seconds = (d2 - d1) / 1000;   // You will get Second Diff between two date
        var diffHrs = Math.floor(seconds / (60 * 60)); // You will get Hours Diff between two date
}

Saturday, October 8, 2016

RetrieveSharedPrincipalsAndAccessRequest + Retrieve User Access for Particualr Record MSCRM

Hi All,

(Eg)

Consider there is an Account, which was shared with some users, if you want to know the users in CRM Plugins or console app, use this


Call the below code as

ProcessSharedUser(Service);


public void ProcessSharedUser(IOrganizationService service)
        {
            PrincipalAccess[] sharedUsersOfAccount = getSharedUsersforAccount("account", new Guid(""), service);
            if (sharedUsersOfAccount.Length > 0)
            {
                for (int i = 0; i < sharedUsersOfAccount.Length; i++)
                {
                    getUserList  sharedUsersOfAccount[i].Principal.Id;
                }
            }
  }

 public PrincipalAccess[] getSharedUsersforAccount(string entityName, Guid accountId, IOrganizationService service)
        {
            RetrieveSharedPrincipalsAndAccessRequest retrieveSharedRequest = new RetrieveSharedPrincipalsAndAccessRequest()
            {
                Target = new EntityReference(entityName, accountId)
            };
            RetrieveSharedPrincipalsAndAccessResponse retrieveSharedResponse = (RetrieveSharedPrincipalsAndAccessResponse)service.Execute(retrieveSharedRequest);

            return retrieveSharedResponse.PrincipalAccesses;
        }

Day 11 - Customizing Option Sets Dropdown Fields with JavaScript

  In this Blog, we will see how to Customizing Option Sets Dropdown Fields with JavaScript label1 = formContext.getAttribute( "bosch_op...