serving the solutions day and night

Pages

Friday, August 30, 2013

MS Dynamics CRM 2011 - EnableRule, ValueRule, OrRule & CustomRule in Ribbon Customizations

ValueRule - Enable the Custom button only when a specific filed on the form has a value.
For example, if the 'Email' field has value then the custom will be enable otherwise it will disable.

/RibbonDiffXml/RuleDefinitions/EnableRules/EnableRule/

<EnableRule Id="DNS.contact.form.EmailValue.EnableRule">
    <ValueRule Field="email" Value="null" InvertResult="true"/>
</EnableRule>

EnableRule for mulitple fields, use 'OrRule', for example

<EnableRule Id="DNS.contact.form.EmailValue.EnableRule">
    <OrRule>
        <Or>
            <ValueRule Field="email" Value="null" InvertResult="true"/>
        </Or>
        <Or>
              <ValueRule Field="leadsourcecode" Value="810520005"/>
        </Or>
    </OrRule>
</EnableRule>
           
EnableRule only works with Equal(=) condition, for different conditions (not equal) use 'InvertResult' attribute.

Refer the above id in the following location /RibbonDiffXml/CommandDefinitions/CommandDefinition/EnableRules

<EnableRule Id="Sample.account.form.CheckFaxValue.EnableRule"/>

CustomRule - call a javascript function based on the result.

<EnableRule Id="DNS.contact.form.EmailValue.EnableRule">
  <CustomRule FunctionName="DisableReportButton" Library="$webresource:dns_JavaScript/reports.js" Default="true" />
</EnableRule>

http://msdn.microsoft.com/en-us/library/gg334317.aspx
http://msdn.microsoft.com/en-us/library/gg328073.aspx
http://msdn.microsoft.com/en-us/library/gg309433.aspx

Thursday, August 29, 2013

Show Pipeline Custom Component in Visual Studio ToolBox

Show Pipeline Custom Component in Visual Studio ToolBox

Add the below code in the Project Build Events

"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\GacUtil.exe" /i "$(TargetPath)" /f
xcopy "$(TargetPath)" "C:\Program Files (x86)\Microsoft BizTalk Server 2010\Pipeline Components" /d /y




MS Dynamics CRM 2011 - Paging Retrieve Multiple Records

QueryExpression query = new QueryExpression(Contact.EntityLogicalName);
EntityCollection coll;
query.PageInfo.PageNumber = 1;
query.ColumnSet = new ColumnSet("firstname", "lastname");
do
{
    int RecordId = 1;
    coll = CRMServiceProxy.RetrieveMultiple(query);
    foreach (Entity e in coll.Entities)
    {
        Console.WriteLine(query.PageInfo.PageNumber + " - " + RecordId + " - " + e.Attributes["firstname"] + " - " + e.Attributes["lastname"]);
        RecordId++;
    }
    query.PageInfo.PageNumber++;
}
while (coll.MoreRecords);


public static OrganizationServiceProxy CRMServiceProxy
        {
            get
            {
                var uri = new Uri(System.Configuration.ConfigurationManager.AppSettings["CrmOrganizationUri"]);

                //Authenticate using credentials of the logged in user;      
                var cnt = new ClientCredentials();
                cnt.Windows.ClientCredential.Domain = System.Configuration.ConfigurationManager.AppSettings["CrmDomain"].ToString();
                cnt.Windows.ClientCredential.UserName = System.Configuration.ConfigurationManager.AppSettings["CrmUserName"].ToString();
                cnt.Windows.ClientCredential.Password = System.Configuration.ConfigurationManager.AppSettings["CrmPassword"].ToString();
                //cnts.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

                var sp = new OrganizationServiceProxy(uri, null, cnt, null);
                sp.EnableProxyTypes();

                return sp;
            }
        }

Avoid Empty Nodes Using Table Looping Functoid in BizTalk

Avoid Empty Nodes Using Table Looping Functoid in BizTalk

You will find out lot of several posts to avoid empty nodes using Table Looping Functoid
My Flat Source File looks like this

SIDNameTitleSub1Sub1FeeSub2Sub2FeeSub3Sub3FeeSub4Sub4FeeSub5Sub5FeeRemark
1ABCDSWA12.50None
2BCDEDBAB13.50C15.00Completed


Flat file converted to the XML (StudentIn.xml) using pipeline components

Mapping


Monday, August 12, 2013

MS Dynamics CRM - Security Role

I have one situation, login user has multiple security roles, if the login user has permission for particular role, show some buttons/fields otherwise the hide buttons/fields.

It is not stright forward to find out the security role, So i wrote one javascript to find out the security role.

<script src="../ClientGlobalContext.js.aspx" type="text/javascript"></script>
<script src="/WebResources/gab_JavaScript/Jquery1.10.2.min.js" type="text/javascript" language="javascript"></script>
<script src="/WebResources/gab_JavaScript/Jason.js" type="text/javascript" language="javascript"></script>

function context() {
    if (typeof GetGlobalContext != "undefined") {
        return GetGlobalContext();
    }
    else {
        if (typeof Xrm != "undefined") {
            return Xrm.Page.context;
        }
    }
}

function GetServerUrl() {
    var Crmurl = window.location;
    var orgName = context().getOrgUniqueName();
    return Crmurl.protocol + "//" + Crmurl.host + "//" + orgName + "/xrmservices/2011/OrganizationData.svc/";
}

Here i am checking the user has "Content Manager" security role or not.

function BookAuditMatch() {
   var ECMRole = CheckUserRole("Book Content Manager");
   if (ECMRole) {
      //Do something
   }
}

This function will get all the user's security role Id, passing security role id to get the security role name. If it match, it is true otherwise false.
function CheckUserRole(roleName) {
    var currentUserRoles = Xrm.Page.context.getUserRoles();
    for (var i = 0; i < currentUserRoles.length; i++) {
        var userRoleId = currentUserRoles[i];
        var userRoleName = GetRoleName(userRoleId);
        if (userRoleName == roleName) {
            return true;
        }
    }
    return false;
}

This function calling odata web service and get the each security role name.
function GetRoleName(userRoleId) {
    var selectQuery = "RoleSet?$top=1&$filter=RoleId eq guid'" + userRoleId + "'&$select=Name";
    var VoterAddress = "";
    var odataSelect = GetServerUrl() + selectQuery;
    //alert(odataSelect);
    var roleName = null;
    $.ajax({
        type: "GET",
        async: false,
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: odataSelect,
        beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
        success: function (data, textStatus, XmlHttpRequest) {
            var result = data.d;
            if (!!result) {
                roleName = result.results[0].Name;
            }
        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            //alert('OData Select Failed: ' + odataSelect);
        }
    });
    return roleName;
}

File Lock Error In Visual Studio

Your project dll is referenced by another project, when you trying to build a project, you will get file lock issue in visual studio,

Unable to copy file "obj\Debug\BizTalk.MSDynamicsCRM2011.Schemas.dll" to "bin\BizTalk.MSDynamicsCRM2011.Schemas.dll". The process cannot access the file 'bin\BizTalk.MSDynamicsCRM2011.Schemas.dll' because it is being used by another process.




if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"

if exist "$(ProjectDir)bin\$(TargetFileName).locked" del "$(ProjectDir)bin\$(TargetFileName).locked"
if exist "$(ProjectDir)bin\$(TargetFileName)" if not exist "$(ProjectDir)bin\$(TargetFileName).locked" move "$(ProjectDir)bin\$(TargetFileName)" "$(ProjectDir)bin\$(TargetFileName).locked"

Register dll in 'C:\Windows\Microsoft.NET\assembly\GAC_MSIL'
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\GacUtil.exe" /i "$(TargetPath)" /f