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>

Nolock & Distinct for Query Expression

Hi All,

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


QueryExpression queryExp = new QueryExpression("account");
queryExp.Nolock = true;
queryExp.EntityName = "account";
var cols = new ColumnSet(new[] { "name", "accountid" });
queryExp.ColumnSet = cols;
queryExp.Distinct = false;
var accounts = service.RetrieveMultiple(queryExp);

Tuesday, May 17, 2016

Load External javascript MSCRM 2011

HI All,

Please find the below code to call external Javasctipt webresources

(Eg)

I have Update function in "new_JQuery"

but now am working in "new_new_JQuery1" function so if i use below code i can directly access Update function from "new_JQuery"  to "new_new_JQuery1".


var url="../WebResources/new_JQuery";
var xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("GET",url,false);
xmlHttp.send();
eval(xmlHttp.responseText);

Monday, May 9, 2016

Filter Activity lookup MSCRM Javascript

Hi All,

Please find the below JS code to filter Lookup Types

In my below Code am filtering requiredattendees, Call the below script in onload function

var lookuptypeIcons = "/_imgs/ico_16_2.gif:/_imgs/ico_16_8.gif";
var lookuptypenames = "contact:2:Contact,systemuser:8:User";
var lookuptypes = "2,8";

if (Xrm.Page.getAttribute("requiredattendees") != null) {
                $("#requiredattendees").focus(function () {
                    var toLookUp = $("img[attrName='requiredattendees']");
                    lookuptypes = "2,8";
                    if (toLookUp.length > 0) {
                        toLookUp[0].setAttribute("lookuptypenames", lookuptypenames);
                        toLookUp[0].setAttribute("lookuptypes", lookuptypes);
                        toLookUp[0].setAttribute("lookuptypeIcons", lookuptypeIcons);
                        toLookUp[0].setAttribute("createpermissiondictionary", "contact:true,systemuser:true");
                        toLookUp[0].setAttribute("DefaultViewId", "5DA08E4B-4493-E111-BEF2-00155DC87C59");
                        toLookUp[0].setAttribute("defaulttype", 2);
                    }
                });

            }

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...