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

            }

Impersonate User in MSCRM 2011/13/15/16

Hi All,

Please find the below c# code to impersonate the user in MSCRM


EntityReference callingUser = new EntityReference
                {
                    LogicalName = "systemuser",
                    Id = {Impersonation User GUID}
                };
OrganizationServiceProxy serviceProxy = (OrganizationServiceProxy)service;
serviceProxy.CallerId = callingUser.Id;


Replace {Impersonation User GUID} with Guid of User to make the Plugin to run as Passing User.

Thursday, May 5, 2016

Convert Text field to URL Field MSCRM 2013/2015/2016

Hi All,

Please find the Below code to Convert Text field to URL Field.

In My case, if user selects a look up value, In onsave operation am saving the value as to the text field as AccountName*AccountnameGuid (initially make the Lookup field enable and make the text field disable)

Once the save operation done. In onload make the Lookup field disable and show the Custom Text to Url Field.

Copy paste the below code and pass the value to "fieldname" to make the value display properly.

After onsave take field should save like below format




After onload the text field will display like below URL Field



function onload(){
converttexttoURL("fieldname");
}

 
function onsave(){
var fldLink = Xrm.Page.data.entity.attributes.get("fieldname");
if (fldLink) {

fldLink.setValue(fldIntroducedTo.getValue()[0].name + "*" + fldIntroducedTo.getValue()[0].id);

fldLink.setSubmitMode("always");
}



function converttexttoURL(fldName) {try {
var getLinkfromTextField = Xrm.Page.data.entity.attributes.get(fldName);

if (getLinkfromTextField && getLinkfromTextField.getValue()) {

var getdatafromfield = fldLink.getValue();

var btnHTML = "<a href='javascript: void(0);' title='" + getdatafromfield.split('*')[0] + "' onclick=\"openAccount('" + getdatafromfield.split('*')[1] + "')\" style='color:blue;text-decoration:underline !important'>" + getdatafromfield.split('*')[0] + "</a>";

var getFieldControl = document.getElementById(fldName);
if (getFieldControl) {

// Set the new HTML to the field
getFieldControl.innerHTML = btnHTML;}
 
// Show Link field

Xrm.Page.ui.controls.get(fldName).setVisible(true);

}
 
} catch (e) {

alert("Error in convertourl- " + e.description);
}
}


function openAccount(accountId) {

if (Xrm && Xrm.Utility && accountId) {

Xrm.Utility.openEntityForm('account', accountId);
}
}
 
 

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