Wednesday, June 6, 2012

Hide Add Existing or hide Add New Ribbon Buttons

Today I had to search once more for how to hide the Add Existing or Add New Ribbon Buttons. I found the article "Ribbon Customization Part-10-Hide ‘Add Existing’ button in Dynamics CRM 2011" which helped me in this case.

Here I want to just add the lines to hide the Add Existing or Add New Buttons for custom entities. In the RibbonDiffXml you can simply add:

Hide Add Existing Button:

 <CustomActions>
  <HideCustomAction Location="Mscrm.SubGrid.[yourentityname].AddExistingAssoc" HideActionId="sample.Mscrm.SubGrid.[yourentityname].AddExistingAssoc.HideAction" />
  <HideCustomAction Location="Mscrm.SubGrid.[yourentityname].AddExistingStandard" HideActionId="sample.Mscrm.SubGrid.[yourentityname].AddExistingStandard.HideAction" />
</CustomActions>


Hide Add New Button: 

<CustomActions> 
   <HideCustomAction Location="Mscrm.SubGrid.[yourentityname].AddNewStandard" HideActionId="sample.Mscrm.SubGrid.contact.[yourentityname].HideAction" />
</CustomActions>



Monday, June 4, 2012

Create your own SetMandatory function instead of using setRequiredLevel directly

It happens again and again that I am searching for SetMandatory in the SDK of MS CRM 2011. Yes, there is setRequiredLevel. But I never use the option of 'recommended' in my projects. I my opinion a field is mandatory or not mandatory. So therefore I have created the following function and put it in my global library:

var CRM_REQUIRED_LEVEL_NORMAL = "none";
var CRM_REQUIRED_LEVEL_RECOMMENDED = "recommended";
var CRM_REQUIRED_LEVEL_REQUIRED = "required";


function SetMandatory(vsFieldName, vbTrueFalse)
{
    try
    {
        if (Xrm.Page.getAttribute(vsFieldName) != null)
        {
            var loFieldName = Xrm.Page.getAttribute(vsFieldName);
            AddDebugMessage("Set mandatory field: '" + vsFieldName + "' to: " + vbTrueFalse.toString());

            if (vbTrueFalse)
            {
                loFieldName.setRequiredLevel(CRM_REQUIRED_LEVEL_REQUIRED);
            }
            else
            {
                loFieldName.setRequiredLevel(CRM_REQUIRED_LEVEL_NORMAL);
            }
        }
        else
        {
            throw ("The following field is not on the form: " + vsFieldName);
        }
    }
    catch (e)
    {
        CatchErrorMessage(e);
    }
}


To use the function simply call the function just created:
SetMandatory("yourfieldname", true);

Or to set the required Level to "normal":
SetMandatory("yourfieldname", false);

By the way AddDebugMessage is my little helper alert message function. It is called if a debug flag is set to true.

Wednesday, May 30, 2012

Dynamics XRM Tools - OData Query Designer

Today I was looking for the OData Query Designer which helped me in the past to generate my JSON or ATOM requests. Now the OData Query Designer has improved and worked for me also in MS CRM 2011 Online. The Query Designer is now part of the Dynamics XRM Tools.



Included in the Dynamics XRM Tools are:
  • OData Query Designer
  • Metadata Browser
  • CRM 4 to CRM 2011 JavaScript Converter
  • Trace Tool (on premise only)
  • Statistics 

If you are using it with another base language than english:
  1. add english as language 
  2. import the solution
  3. change your user options to english
  4. now it should work

For more information please visit dynamicsxrmtools.codeplex.com

Tuesday, May 29, 2012

Custom Time Interval in MS CRM 2011 Activities

I found a jscript solution to create custom time interval in MS CRM 4.0. As I needed it for MS CRM 2011 activities I slightly changed the solution. Standard behaviour is a 30 minute interval. With this solutions you can change it to whatever interval you like.

First add the function to a global jscript library


function SetDateTimeInterval(voDateTimeField, viInterval)
{
    try
    {
        //Check the existence of the datetime field. It may not be included in a quick create form!
        if (voDateTimeField != null)
        {
            if (voDateTimeField.getFormat() == "datetime")
            {
                //The new interval in minutes.
                var lsInterval = viInterval;
                var loTables = document.getElementById("scheduledstart").getElementsByTagName("table");
               
                if ((loTables != null) && (loTables.length > 0))
                {
                    var loTable = loTables[1];
                    //Remove all existing values from the selection box while (table.firstChild != null)
                    {
                        loTable.removeChild(loTable.firstChild);
                    }
                    //Add the new values
                    for (hour = 0; hour < 24; hour++)
                    {
                        for (min = 0; min < 60; min += lsInterval)
                        {
                            var row = loTable.insertRow();
                            var cell = row.insertCell();
                            var time = ((hour < 10) ? "0" : "") + hour + ":" + ((min < 10) ? "0" : "") + min;
                            cell.setAttribute("val", time);
                            cell.innerText = time;
                        }
                    }
                }
            }
        }
    }
    catch (e)
    {
        CatchErrorMessage(e);
    }
}


Call the function from a local jscript library e.g. appointment

function SetDateTimeIntervalTo15Min()
{
    try
    {
        var lsFieldStartTime = "scheduledstart";
        var loFieldStartTime = Xrm.Page.getAttribute(lsFieldStartTime);

        //Set Interval to 15 minutes
        var liInterval = 15;

        if (loFieldStartTime != null)
        {
            SetDateTimeInterval(loFieldStartTime, liInterval);
        }
    }
    catch (e)
    {
        CatchErrorMessage(e);
    }
}


Tuesday, May 15, 2012

Fetch XML through Advanced Find

It is small but great feature to use Advanced Find to create your Fetch XML statement. 

1. choose the entity you need
2. add or change the search attributes

3. add or change the columns "Spalten bearbeiten"


4. preview your result using the button "results" / "Ergebnisse"
5. download the Fetch XML / "FetchXML herunterladen"

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="account">
    <attribute name="name" />
    <attribute name="address1_city" />
    <attribute name="telephone1" />
    <attribute name="accountid" />
    <order attribute="name" descending="false" />
    <filter type="and">
      <condition attribute="statecode" operator="eq" value="0" />
      <condition attribute="address1_city" operator="eq" value="Zürich" />
    </filter>
  </entity>
</fetch>


I have used it to create the fetch XML statement for the AddExisting filter.

Wednesday, May 2, 2012

Filter the AddExisting functionality

A great how to article to filter the AddExisting Button with a fetch XML resultset.

 
To build the fetch XML you can use the built in advanced find functionality.