Friday, October 14, 2016

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;
        }

Monday, August 1, 2016

MSCRM + Pass UnSecure Configuration from Plugin Registration Tool to Plugins

Hi All,

Please find the below steps to pass value from Unsecure Plugin Configuration to Plugin Code

<UnSecureConfiguration>
  <setting name="GUID1">
    <value>131F1519-000-E511-9875-000D3AA0AC11</value>
  </setting>
  <setting name="GUID2">
    <value>1808CB50-17B9-E511-94RE5-000D3000AC11</value>
  </setting>
</UnSecureConfiguration>      

Plugin C# Code to Retrieve Values from Unsecure Plugin Configuration

private static Guid GetGUID1 = Guid.Empty;
private static string GetGUID2 = null;

private static string GetValueNode(XmlDocument doc, string key)
        {
            XmlNode node = doc.SelectSingleNode(String.Format("UnSecureConfiguration/setting[@name='{0}']", key));

            if (node != null)
            {
                return node.SelectSingleNode("value").InnerText;
            }
            return string.Empty;
        }


var pluginConfig = string.IsNullOrWhiteSpace(unsecureConfig) ? secureConfig : unsecureConfig;
            try
            {
                if (!string.IsNullOrWhiteSpace(pluginConfig))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(pluginConfig.ToString());
                    GetGUID1 = new Guid(GetValueNode(doc, "GUID1"));
                    GetGUID2 = GetValueNode(doc, "GUID2");
                }
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(ex.Message);
            }

Monday, June 27, 2016

Fetch XML NoLock

Hi All,

We have faced an issue that Retrieve and Retrieve Multiple (Fetch XML) plugins fetching record too slow when there are more concurrent user access the system , so we have used nolock to overcome.



<fetch mapping="logical" no-lock="true">

</fetch>

How to Run Microsoft Flow for Every one Month

Introduction: In this Blog we will see how to Run Microsoft Flow for Every one Month. Implementation Steps:   1. Navigate to  https://make.p...