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

Wednesday, July 31, 2013

Dynamics CRM - Cross-Site Scripting Filter

In CRM, if your customization fetch xml contain extra attribute name which is does not belong in the Saved View, then IE will throw
"Internet Explorer has modified this page to help prevent cross-site scripting. Click here for more information... "



Example
Saved View contains - firstname, lastname
Cusomization fetch XML contain middlename
var fetchBaseXML = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">';
            fetchBaseXML += '    <entity name="contact">';
            fetchBaseXML += '        <attribute name="middlename" />';
            fetchBaseXML += '        <attribute name="lastname" />';
            fetchBaseXML += '        <attribute name="firstname" />';
           
Solution 1
Remove the attribute name from the customization fetch OR Add the attribute name in the Saved View.

Solution 2
Click Tools > Internet options > Security and click the Custom Level... button.
Scroll down the list and click the Disable radio button for the Enable XSS-filter option.
Restart the browser.
Click the Submit button again in the Report Administration screen in Maximo, and the SmartCloud Cost Management reports are now displayed.

Saturday, June 8, 2013

Retrieve Multiple Dynamics CRM 2011 Entity Records from BizTalk 2010 Server

Retrieve Multiple Dynamics CRM 2011 Entity Records from BizTalk 2010 Server
1)Create new map (MCRM_List.btm)

2) Added <Fetch><Query/></Fetch> schema in the SAuditXML.xml schema

3)Select Source Schema (SAuditXML), Desitnation Schema(DNS_BTS_CRM.organixationservice_schemas_microsoft_com_xrm_2011_contracts_services -> RetrieveMultiple)

4)Make Query(source) link to FetchExpression->Query(Destination)

Create/Update/Delete Dynamics CRM 2011 Entity Record from BizTalk 2010 Server

Create Dynamics CRM 2011 Entity Record from BizTalk 2010 Server

1)Create new map (MCRM_Create.btm)

2)Select Source Schema (SAuditXML), Desitnation Schema(DNS_BTS_CRM.organixationservice_schemas_microsoft_com_xrm_2011_contracts_services -> Create)

3)Rename Page name (Enity), make EnityName(source) link to LogicalName(Destination)


Thursday, June 6, 2013

Dynamics CRM 2011 and BizTalk 2010 Server Integration - Exception


Exception 1
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:entity. The InnerException message was 'There was an error deserializing the object of type Microsoft.Xrm.Sdk.Entity. End element 'value' from namespace 'http://schemas.datacontract.org/2004/07/System.Collections.Generic' expected. Found element 'Value' from namespace 'http://schemas.microsoft.com/xrm/2011/Contracts'. Line 1, position 4190.'. Please see InnerException for more details.

Solution
Data Type is wrong.

For example, In CRM attribute type is int, but in BizTalk Schema contains string and in the Map, Script Functionid contains <xsl:attribute name="xsi:type"><xsl:value-of select="'xs:string'" /> , the CRM will throw the above error.

Change to  int in the schema and <xsl:attribute name="xsi:type"><xsl:value-of select="'xs:int'" /> in the Map