Author Archives: Vikranth

How – To Series 12: Another restriction from Field Leve Security….!!!?

Hi,
We all know that only OOB fields have been restricted from Field Level Security and all the custom fields can have Field Level Security. However, today i tried creating a new field of type “Single Line of Text” of format”EMail” with “Field Level Security” enabled.To my surprise I can see the following error:

And this is the error message in the Log file: “This field is not
securable”

I raised this issue with MSConnect here . Need to findout whether its bug or by design.

How-To Series 11: How To Trigger a plugin on Sharing a Record and Send An EMail

Hi All,
Today I have seen one forum post asking for Sending an email on Sharing a record. So, thought of implementing the same and blog it over here.
When a record is shared, a “PrincipalObjectAccess” record will be created in DB. However, we can’t register a plugin on “Create” Message for “PrincipalObjectAccess” entity. Instead, we can register it on “GrantAccess” message which will be triggered on sharing the record. So, simply register your plugin as follows:

Following is the piece of plugin code to get the details of record being shared and the users/team for whom the record has been shared. Here I am trying to send an email to the user for whom the record has been shared.

// The InputParameters collection contains all the data passed in the message request.if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”] is EntityReference)

{// Entity Record which has been shared
EntityReference sharedRecord = ((EntityReference)context.InputParameters[“Target”]);
// System User for whom the record has been shared
EntityReference sysUser = ((PrincipalAccess)context.InputParameters[“PrincipalAccess”]).Principal;

// System User ID who has shared the record
Guid fromUserId = context.UserId;
// Send An EMail
SendEmail(service, sysUser, fromUserId, sharedRecord);
}

I have shared the entire plugin code over here: Here

PS: If we have shared the record to multiple users then this plugin will also be triggered multiple times. This means that, if you have shared a record to 5 users then an email will be sent to 5 users seperately not in a single shot.

Hope it helps…!!! 🙂

How-To Series 10: How To get Selected Record Entity Name from Activities or Queue Item Entity Home Page Grid

Hi All,
           We know that we can use “SelectedEntityTypeName” to get the selected record’s “Entity Name” in a Grid. This is useful for every entity with an exception to couple of entities like “Queue Item” and “Acitivity” HomePage Grids as these will display records belongs to more than one entity. For an instance, “Activities” will display “EMail, Phonecall, Appointment etc..”. 
           So, if you want to retireve the selected record’s entity name then use the following function. The following function requires all the views in the grid to have the entity name as one of the column at the same location. It will retrieve selected record’s Id along with its entity name. Its the same way we used to do in CRM 4.0’s ISV.Config.
function ShowSelectedIdsWithEntityName()
{
var selectedrecords = document.all[‘crmGrid’].InnerGrid.SelectedRecords;
for (var i=0; i < selectedrecords.length; i++)
{
//This will return the selected record guid
alert(“Selected Record Id: “+selectedrecords [i][0]);
// This will return the 5th column data. OOB, in “Queue Item” entity “Type(Entity Name)” is the 5th column for all views.
alert(“Selected Entity Name: “+selectedrecords [i][3].cells[4].innerText);
}
}

Following is for “Queue Item” entity.
 

Hope it helps….

Cheers
Vikranth P.

How-To Series 9: Dynamic Ribbon Controls using CommandProperty – Infinite loop issue

There is nice article from MS Blog on creating dynamic ribbons in CRM 2011 http://blogs.msdn.com/b/crm/archive/2011/03/30/create-dynamic-ribbon-controls.aspx. I have followed the same approach to create a split button. However, here in my case we want to have the Menu XML dynamically generated based on some entity data. However, there was a problem when we tried to do that using ODATA query. There was nothing wrong in the code. ODATA query was able to retrieve the data and pass the result set to the call back method to populate ribbon split button. However, once the population is done in the code, control is moving back to starting point in the code(function DynamicMenu(CommandProperties)). It’s going into infinite loop.
function DynamicMenu(CommandProperties)
{
getData(CommandProperties, SuccessCallBack, ErrorCallBack);
}
function getData(CommandProperties, SuccessCallBack, ErrorCallBack)
{
//ODATA Stuff
success: function (data, textStatus, XmlHttpRequest)
        {
              // Success Call Back
       SuccessCallBack(CommandProperties,data);
        },
//ODATA Stuff
}
function SuccessCallBack(CommandProperties,data)
{
// Split Button population stuff
}
After bit(I can say a lot of) of struggle I felt it might be due to Asynchronous AJAX call in the script. To verify that I have commented ODATA call and kept “SetTimeOut(method(),4000)” in my code and did populate split button using static MenuXML. It’s again going to infinite loop. This time I have commented  “SetTimeOut” method too. Now, it’s working perfectly.
So, i thought of replacing ODATA Async Call with SOAP Synchronous call. This time it worked like a charm.….!!!!!! J
Hope it helps…!!!!
Cheers
Vikranth Pandiri

How To – Series 8: Cross Domain Issue while working with CRM 2011 Web Services in JScript

Back to blogging after long time. Recently I faced a “Cross Domain” issue while working with Jscript ODATA query. Below is the code which I have used:
    var ODATA_ENDPOINT = “/XRMServices/2011/OrganizationData.svc”;
    var context = GetGlobalContext();
    var serverUrl = context.getServerUrl();
   
    //Asynchronous AJAX function to Retrieve a CRM record using OData
    $.ajax({
        type: “GET”,
        contentType: “application/json; charset=utf-8”,
        datatype: “json”,
        url: serverUrl + ODATA_ENDPOINT + “/AccountSet?$filter=Address1_City eq ‘Redmond'”,
        beforeSend: function (XMLHttpRequest)
        {
            XMLHttpRequest.setRequestHeader(“Accept”, “application/json”);
        },
        success: function (data, textStatus, XmlHttpRequest)
        {
              // Success Call Back
        },
        error: function (XmlHttpRequest, textStatus, errorThrown)
        {
              // Error Call Back
        }
    });
The REST End point “url “ which I am passing in the above code is: http://<server>/<orgname>/XRMServices/2011/OrganizationData.svc/AccountSet?$filter=Address1_City eq ‘Redmond’.This code only works when we open CRM records using CRM “Server” name. It fails in other cases like when we open it using IP Address or localhost. The primary reason for this is due to “Cross Domain Policy”. The blocker is the REST End point which we are using. 
So, I thought of replacing server name with IP Address as follows.
I ran it in the browser…. It worked…!!!! J
So, I got a simple solution. 
Use the following instead of getting “ServerUrl” from the context object.
    var serverUrl = window.location.protocol + “//” + window.location.host + “/” + context.getOrgUniqueName();
Here we just need to use the window.location property to get the current window protocol and host and build the REST Endpoint.
Hope it helps…!!!! Please let me know if we have any other alternative solution. 
Cheers
Vikranth Pandiri.

How To – Series 7: How To override(Enable, Disable, Show, Hide, Custom Logic) Out of the Box HomePageGrid ribbon elements – CRM 2011

Hope my earlier posts on Ribbon elements helps you. In this post we will see how to Enable/Disable Out of the Box ribbon elements in Dynamics CRM 2011. After going through the SDK, it seems there is no direct solution to override existing <CommandDefinition>. However, the documention says using <CustomAction> we can Add or Replace items in the ribbon. It gives me an idea to replace existing OOB(Out of the Box) ribbon item with Custom ribbon item and define our own <CommandDefinition> for that. At the same time we can also go with the OOB <CommandDefinition>. Lets see how we can do that stuff.

Lets consider “Edit” ribbon item on the “Account” entity “HomePageGrid”. I want to disable this “Edit” button when user selects more than one record in the sub grid(i.e I don’t want “Bulk Edit” feature for Account records). The same can be achieved with security roles. However, for the sake of simplicity and to focus more on how we can override <EnableRules>, <DisplayRules> and <Actions> for an OOB item I have considered this scenario.

 

Step 1:

 

Open “accounribbon.xml” file from the “sdksamplecodecsclientribbonexportribbonxmlexportedribbonxml” location in the CRM 2011 SDK.

 

Below is the definition for “Edit” button

 

<Button Id=”Mscrm.HomepageGrid.account.Edit” ToolTipTitle=”$Resources:Ribbon.HomepageGrid.MainTab.Management.Edit” ToolTipDescription=”$Resources(EntityDisplayName):Ribbon.Tooltip.Edit” Command=”Mscrm.EditSelectedRecord” Sequence=”20″ LabelText=”$Resources:Ribbon.HomepageGrid.MainTab.Management.Edit” Alt=”$Resources:Ribbon.HomepageGrid.MainTab.Management.Edit” Image16by16=”/_imgs/ribbon/Edit_16.png” Image32by32=”/_imgs/ribbon/edit32.png” TemplateAlias=”o1″ />

 

 

Below is the <CommandDefinition> for “Edit” button.

 

 

<CommandDefinition Id=”Mscrm.EditSelectedRecord”>

 

        <EnableRules>

 

          <EnableRule Id=”Mscrm.CheckBulkEditSupportForEntity” />

 

          <EnableRule Id=”Mscrm.VisualizationPaneNotMaximized” />

 

        </EnableRules>

 

        <DisplayRules>

 

          <DisplayRule Id=”Mscrm.BulkEditPrivilege” />

 

          <DisplayRule Id=”Mscrm.WriteSelectedEntityPermission” />

 

        </DisplayRules>

 

        <Actions>

 

          <JavaScriptFunction FunctionName=”Mscrm.GridRibbonActions.bulkEdit” Library=”/_static/_common/scripts/RibbonActions.js”>

 

            <CrmParameter Value=”SelectedControl” />

 

            <CrmParameter Value=”SelectedControlSelectedItemReferences” />

 

            <CrmParameter Value=”SelectedEntityTypeCode” />

 

          </JavaScriptFunction>

 

        </Actions>

 

      </CommandDefinition>

 

 

Copy both of the definitions and we gonna use them in the next steps.

 

Step 2:

 

Add “Account” entity to a solution. Export it. Open “Customizations.xml” file.

 

Go to <EnableRules> section and add following <EnableRule> which will return “true” when only one item is selected in the sub grid.

 

 

   <EnableRule Id=”Sample.account.grid.OnSelection.EnableRule”>

 

              <SelectionCountRule AppliesTo=”SelectedEntity” Maximum=”1″ Minimum=”1″/>

 

            </EnableRule>

 

 

Step 3:

 

 

Go to <CommandDefinitions> section and add copied <CommandDefintion> form the Step1. Rename “Id” value to “Sample.account.grid.DisableExisting.Command”

 

<CommandDefinition Id=”Mscrm.EditSelectedRecord”>

 

        <EnableRules>

 

          <EnableRule Id=”Mscrm.CheckBulkEditSupportForEntity” />

 

          <EnableRule Id=”Mscrm.VisualizationPaneNotMaximized” />

 

        </EnableRules>

 

        <DisplayRules>

 

          <DisplayRule Id=”Mscrm.BulkEditPrivilege” />

 

          <DisplayRule Id=”Mscrm.WriteSelectedEntityPermission” />

 

        </DisplayRules>

 

        <Actions>

 

          <JavaScriptFunction FunctionName=”Mscrm.GridRibbonActions.bulkEdit” Library=”/_static/_common/scripts/RibbonActions.js”>

 

            <CrmParameter Value=”SelectedControl” />

 

            <CrmParameter Value=”SelectedControlSelectedItemReferences” />

 

            <CrmParameter Value=”SelectedEntityTypeCode” />

 

          </JavaScriptFunction>

 

        </Actions>

 

      </CommandDefinition>

 

 

Add    <EnableRule Id=”Sample.account.grid.OnSelection.EnableRule”/> to the <EnableRules> section.

 

 

<CommandDefinition Id=”Mscrm.EditSelectedRecord”>

 

        <EnableRules>

 

          <EnableRule Id=”Mscrm.CheckBulkEditSupportForEntity” />

 

          <EnableRule Id=”Mscrm.VisualizationPaneNotMaximized” />

 

          <EnableRule Id=”Sample.account.grid.OnSelection.EnableRule”/>

 

        </EnableRules>

 

        <DisplayRules>

 

          <DisplayRule Id=”Mscrm.BulkEditPrivilege” />

 

          <DisplayRule Id=”Mscrm.WriteSelectedEntityPermission” />

 

        </DisplayRules>

 

        <Actions>

 

          <JavaScriptFunction FunctionName=”Mscrm.GridRibbonActions.bulkEdit” Library=”/_static/_common/scripts/RibbonActions.js”>

 

            <CrmParameter Value=”SelectedControl” />

 

            <CrmParameter Value=”SelectedControlSelectedItemReferences” />

 

            <CrmParameter Value=”SelectedEntityTypeCode” />

 

          </JavaScriptFunction>

 

        </Actions>

 

      </CommandDefinition>

 

 

 

Step 4:

 

 

Add following <CustomAction> to the <CustomActions> section:

 

 

          <CustomAction Id=”Sample.account.grid.DisableExisting.CustomAction” Location=”Mscrm.HomepageGrid.account.Edit” Sequence=”21″>

 

            <CommandUIDefinition>

 

              <Button Id=”Mscrm.HomepageGrid.account.Edit” Command=”Sample.account.grid.DisableExisting.Command” LabelText=”$Resources:Ribbon.HomepageGrid.MainTab.Management.Edit” Alt=”$Resources:Ribbon.HomepageGrid.MainTab.Management.Edit” ToolTipTitle=”$Resources:Ribbon.HomepageGrid.MainTab.Management.Edit” ToolTipDescription=”$Resources(EntityDisplayName):Ribbon.Tooltip.Edit” TemplateAlias=”o1″ Image16by16=”$webresource:new_/icons/TIcon16x16.png” Image32by32=”$webresource:new_/icons/TIcon32x32.png” />

 

            </CommandUIDefinition>

 

          </CustomAction>

 

 

Here we need to carefully observe what we have done to replace existing “Edit” button with our own Custom Button.

 

<CustomAction Id=”Sample.account.grid.DisableExisting.CustomAction” Location=”Mscrm.HomepageGrid.account.Edit” Sequence=”21″>

 

 

Here I have given  unique id for the <CustomAction> and for the “Location” attribute I have placed “Id” of the OOB “Edit” button only. I haven’t kept “._children”. This makes all the difference…

 

 

<Button Id=”Mscrm.HomepageGrid.account.Edit” Command=”Sample.account.grid.DisableExisting.Command” LabelText=”$Resources:Ribbon.HomepageGrid.MainTab.Management.Edit” Alt=”$Resources:Ribbon.HomepageGrid.MainTab.Management.Edit” ToolTipTitle=”$Resources:Ribbon.HomepageGrid.MainTab.Management.Edit” ToolTipDescription=”$Resources(EntityDisplayName):Ribbon.Tooltip.Edit” TemplateAlias=”o1″ Image16by16=”$webresource:new_/icons/TIcon16x16.png” Image32by32=”$webresource:new_/icons/TIcon32x32.png” />

 

 

Here, I have given OOB “Edit” button “Id” as the “Id” for the new item. Do remember that, “Id” value in the <Button> should be same as “Id” value in the <CustomAction>. In other words the new Ribbon Item should have same “Id” as the OOB item.

 

For the “Command” attribute I am planning to use OOB Command that has been defined for the “Edit” item. I am planning to use OOB features and in addition to that I am planning to have my own <EnableRules>, <DisplayRules> and <Actions> rules. Feel free to use your own Command if you require to.

 

For remaining attributes also I wish to go with OOB except for the Images. Here I want to show images from my web resource.

 

Now, Import the solution with these changes to your system. Below is the result:

When no recod is selected:

When One record is selected:
When multiple records are selected
In this way we can override OOB behaviors and visualizations for OOB ribbon elements. If you want to have more complex queries for the <EnableRule> then we can use <CustomRule> to call a JScript function. Please see my earlier post here: http://howto-mscrm.com/2011/04/how-to-series-6-how-to-use-customrule.html on how to use <CustomRule> with “HomePageGrid”.
Hope it helps everyone. 🙂

Cheers…!!!
Vikranth Pandiri.

How To – Series 6: How To Use “CustomRule” to Enable/Disable HomePageGrid Buttons- CRM 2011

 

In the earlier post here we have seen how to use <ValueRule> to retrieve a field value from the CRM form and Enable/Disable Custom Button based on that value. What if we want to do the same thing with “HomePageGrid” also like based on a particular value from the selected record in the Grid, Enable/Disable a Custom Button? Can we use <ValueRule> for the same?? The answer is big “No…!!!” Instead, we can use <CustomRule> wherein we can call a JavaScript function to do the required stuff.
For this post also, I am doing required stuff for “HomePageGrid” on top of the following SDK walkthrough: Walkthrough: Add a Custom Button to an Existing Group for a Specific Entity . Below is the result of SDK sample for Account Home Page Grid:
Custom button “Hello Ribbon” will be enabled when only one Account record is selected. Following is the code snippet for that:
<EnableRule Id=”Sample.account.grid.OneSelected.EnableRule”>
  <SelectionCountRule AppliesTo=”SelectedEntity” Maximum=”1″ Minimum=”1″ />
</EnableRule>
Now, let’s consider a scenario where we want to enable the “Hello Ribbon” button when only one Account record is selected and the selected record should have “Fax” value. We will see what are all the steps we need to follow to accomplish this.
Step 1: Retrieve the selected Item’s GUID value
Step2: Use the resultant GUID value to retrieve “Fax” field value using “REST” or “SOAP” calls
Step 1:
Inorder to retrieve selected item’s GUID value, we can use the following:
<CrmParameter Value=”SelectedControlSelectedItemCount” />
<CrmParameter Value=”FirstSelectedItemId” />
The first one returns an array of GUIDs for the selected items and the latter one returns GUID of the first item in the selected items.
<CrmParameter Value=”SelectedControlAllItemCount” />
Using this one we can get a count of selected items.
Step 2:
Use <CustomRule> to call java script function by passing the selected GUID value and it’s count. Following is the code snippet to do that:
            <EnableRule Id=”Sample.account.grid.SelectedRowValueCheck.EnableRule”>
              <CustomRule FunctionName=”IsExist” Library=”$webresource:new_CheckFieldValue.js”>
                <CrmParameter Value=” SelectedControlSelectedItemCount” />
                <CrmParameter Value=”FirstSelectedItemId” />
              </CustomRule>
            </EnableRule>
Here, “FunctionName” refers to Java Script method and “Library” refers to Java Script web resource. And the <CrmParameter> defined will pass it’s returned Value to the <CustomRule>’s function as parameters.
Let’s go define “IsExist” method in “new_CheckFiledValue.js” web resource as follows:
function IsExist(rowscount, firstselectedid) {
    if (rowscount == 1) {
        var ValueExist = ReturnValue(firstselectedid);
        return ValueExist;
    }
    else {
        return false;
    }
}
Observe the “IsExist” function’s prototype. It has two parameters. The first one “rowscount” refers to first <CrmParameter> and the second one referes to second <CrmParameter>. In the definition, I am calling a method “ReturnValue” with “firstselectedid” as the parameter when “rowscount” is 1. If not, returning “false”. In the “ReturnValue” method I am planning to retrieve “Fax” field value based on the GUID from the “firstselectedid” parameter using REST based web service call.
function ReturnValue(firstselectedid) {
    var context = Xrm.Page.context;
    var serverUrl = context.getServerUrl();
    var ODATA_ENDPOINT = “/XRMServices/2011/OrganizationData.svc”;
    var ODATA_Filter = “/AccountSet?$select=Fax&$filter=AccountId/Id eq (guid'” + firstselectedid + “‘)”;
    var jsonEntity = window.JSON.stringify(CRMObject);
    $.ajax({ type: “GET”,
        contentType: “application/json; charset=utf-8”,
        datatype: “json”,
        url: serverUrl + ODATA_ENDPOINT + ODATA_Filter,
        beforeSend: function (XMLHttpRequest) {
             XMLHttpRequest.setRequestHeader(“Accept”, “application/json”);
        },
        success: function (data, textStatus, XmlHttpRequest) {
            var faxValue = data[“d”];
            if (faxValue != null)
                return true;
            else
                return false;
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            return false;
        }
    });
}
This function returns “True” if “Fax” field has value else “False”.
PS: We need to refer “JQuery” and “JSON” libraries in our Java Script web resource to use REST end points. However, I am still struggling to find out how to refer “JQuery” and “JSON” libraries in our Java script web resource as we are not calling the functions as part of any event. Right now, I am working on an “Online” deployment. If it is On-Premise environment, we could easily call “JQuery” and “JSON” libraries as external files the same way we used to do in CRM 4.0. Anyways, I will come back here once I find a solution.
Hope it helps in giving a basic idea on how to use <CustomRule> and how to Enable or Disable HomePageGrid’s Button based on a condition.

How To – Series 5: How To Use “ValueRule” and “OrRule” in Ribbon Customizations – CRM 2011

 

Hello everyone,

 

This is my first blog post on Dynamics CRM 2011. I have been going through Dynamics CRM 2011 SDK and it has fantastic stuff to learn. I went through the Walkthrough: Add a Custom Button to an Existing Group for a Specific Entity Ribbon customization stuff in the SDK and able to do it. In that walkthrough, by using “CrmClientTypeRule” and “FormStateRule” rules custom button on the Form(not HomePageGrid)  has been enabled only for “Web Client” and for “Existing Records”. This is the result of SDK sample:

Now, In this post I would like to add few more things on how to use “ValueRule” and “OrRule” rules with “EnableRules”.

Lets consider, if we want to enable the Custom button only when a specific filed on the form has a value. In that scenario, we can use “ValueRule” which can retrieve a specific field value on the form. Assume that we have to show Custom button only when “Fax” filed has value. In that case we can think of two approaches. One is, if “Fax” field is null then disable the Custom Button and the other one is, if “Fax” field has “anyvalue” then “Enable” the custom button. However, for ribbon customizations we have only “EnableRule”. And certainly “EnableRule” only works with “Equality” condition. So, In order to support different conditions we have one useful attribute called “InvertResult” which negates the result(Instead of looking for “not equal” condition, go with equal condition and use “InvertResult”).

 

Following the piece of code we need to place it under //RibbonDiffXml/RuleDefinitions/EnableRules/EnableRule/

 

            <EnableRule Id=”Sample.account.form.CheckFaxValue.EnableRule”>

<ValueRule Field=”fax” Value=”null” InvertResult=”true”/>
</EnableRule>

Here I have used unique Id for the “EnableRule” which can be used to refer in the “CommandDefinition”. For the “ValueRule”, I have defined three attributes. “Field” refers to the schema name of particular field on the form from which we are trying to retrieve a value. “Value” attribute will hold user given value which will be checked against “Field” attribute’s value for equality. In our case, I decided to go with “null” check condition and “InvertResult”.  So, I have given “null” as the value and for the third attribute “InvertResult”, I have given “true” as the value. Whenever “Fax” filed has value then the returned value from “ValueRule” is “True”(as we are using Invert Result) and “False” if it is “null”.

 

After placing above code, refer the id in the following location //RibbonDiffXml/CommandDefinitions/CommandDefinition/EnableRules as

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

Now, export the solution and publish it. Below will be the result when Fax doesn’t have any value:

And when “Fax” field has a value:

That’s cool. With single line additional code we can enable/disable custom button based on field value.

Now, I thought of checking with “Option Set” fields and want to whether it considers “Selected Value” or “Selected Text”. Certainly, it is “Selected Value” by default. Below is the piece of code I wrote:

<EnableRule Id=”Sample.account.form.CheckContactValue.EnableRule”>
<ValueRule Field=”address1_addresstypecode” Value=”1″/>
</EnableRule>

<EnableRule Id=”Sample.account.form.CheckFaxValue.EnableRule”>
<ValueRule Field=”fax” Value=”null” InvertResult=”true”/>
</EnableRule>

And
<EnableRule Id=”Sample.account.form.CheckFaxValue.EnableRule”/>
<EnableRule Id=”Sample.account.form.CheckContactValue.EnableRule”/>

Below is the result:

When “Address Type” is selected as “Bill To(Value:1):

 

And when other than “Bill To” is selected:

 

This is fine and as expected. And one more thing we need to observe “EnableRule” placed under  RibbonDiffXml/CommandDefinitions/CommandDefinition/EnableRules are by default uses “and” filter. If I remove “Fax” filed value and keep “Bill To” as the “Address Type”, the custom button will be disabled. Check the below screenshot:

 

So, what if we want to go with “or” condition??? Certainly, we do have “OrRule” which can be used for this purpose. Instead of having two separate “EnableRule” for each “ValueRule”, we can have one “EnableRule” with collection of “ValueRule” under “OrRule”. Below is the piece of code we need to have under //RibbonDiffXml/RuleDefinitions/EnableRules/EnableRule/:

<EnableRule Id=”Sample.account.form.OrRule.EnableRule”>
<OrRule>
<Or>
<ValueRule Field=”fax” Value=”null” InvertResult=”true”/>
</Or>
<Or>
<ValueRule Field=”address1_addresstypecode” Value=”1″/>
</Or>
</OrRule>
</EnableRule>

And refer the “Id” at the following: //CommandDefinitions/CommandDefinition/EnableRules
<EnableRule Id=”Sample.account.form.OrRule.EnableRule”/>

Below is the result with “OrRule”:

 

Now, the question arises what if I have complex query and based on its result custom button should be enabled/disabled??? The answer is, we do have one more feature called “CustomRule” using which we can call a Java Script function and based on the result(should be Boolean) we can enable/disable a custom button. In this coming post I will show how to use that Rule and in which scenarios it will be more useful.

This post gives basic idea on how to use “ValueRule” and “OrRule” in Ribbon Customizations. Hope it helps…!!! J

How To – Series 4: How to make an Associated View IFrame Mandatory

Sometimes, we came across situations to make an Associated View IFrame to be mandatory. However, it is very easy to implement. There are two approaches. First one is, using Java Script to call a web service and check whether current record has at least one associated record. And the second approach is just check whether an IFrame which is used to display associated records has at least one record in it’s grid. The latter approach is very easy to implement and here we go:
1.       In the onSave event of crmForm, just check how many records the IFrame grid has
2.       If the count is less than one, cancel the Save event and alert the user
3.       Set the focus to the “Add Existing Button” of the crmGrid.
function ValidateIFrame()
{
if (crmForm.all.IFRAME_ MyIFrame.readyState == “complete”)
{
if (document.frames(“IFRAME_ MyIFrame”).document.all[‘crmGrid’].InnerGrid.NumberOfRecords < 1)
{
event.returnValue=false;
alert(“Please Select Records”);
var oaddexist=document.frames(‘IFRAME_ MyIFrame’).document.getElementById(‘<id of the add existing button>’);
if(oaddexist)
{
oaddexist.focus();
}
}
}
}
}
if(crmForm.all.IFRAME_MyIFrame)
{
ValidateIFrame();
}

Hope it helps…

Thanks
Vikranth P.