Showing posts with label CRM 2011. Show all posts
Showing posts with label CRM 2011. Show all posts

Sep 11, 2013

Microsoft CRM 2011, import CSV file with entity references (lookups)

While most of the time you probably could use a LookupMaps to set up an entity references in you import maps, you may come to situation there you want put actual ID's (references) in your CSV file. So, the tricky part here is the format. To create EntityReference you need entity type name and it's GUID. How would you put that into CSV string? The answer is like this:

"entity_type_name,{SOMEGUID-3FBA-47E5-ADD0-F6078ACDABB8}"

Note that surrounding quotes are required, because of the comma.

Aug 7, 2013

Microsoft CRM 2011, hide system Save menu

Recently we were asked if it is possible to disable a standard 'Save' menu of Microsoft CRM 2011, since all data on forms is read-only anyway. So, after some searching I've found sample code how to do this. The key was to use "top" property which is containing parent frame which is necessary, since our code (called in "OnLoad" form event) is executing in inner frame. With some modifications this is what finally worked out for me:

var disableSaveMenu = function() {
    // your entities names
    var entities = ["account", "contact" /* add as necessary */];

    var i;
    for(i = 0; i < entities.length; i++) {
        var ent = entities[i];
        var save = top.document.getElementById(ent + "|NoRelationship|Form|Mscrm.Form." + ent + ".MainTab.Save");
        if(save != null) {
            save.style.display = 'none';
            break;
        }
    }
    
    // hide 'File' menu, additional 'Save' is also located there
    var jewel = top.document.getElementById("jewelcontainer");
    if(jewel != null) {
        jewel.style.display = 'none';
    }
};

Aug 6, 2013

Microsoft CRM 2011, automatically load all subgrids

Microsoft CRM 2011 doesn't load by default data in all of the subgrids if they count exceed 4, displaying 'To load ... records, click here' message. It's actually extremely annoying.

It's not possible to change this behaviour with standard tools (i.e. via control preferences). So I've found how to do it using JavaScript function call on form OnLoad event. Unfortunatelly it did't worked in my case. For some reason the moment then OnLoad event was fired, the from subgrids were, apparently, not initialized on the form. I've decided then to call the function with a little delay:

var autoLoadSubgrids = function() {
    var maxAuto = 4;
    var loadDelay = 1000;

    var subgrids = Xrm.Page.ui.controls.get(function (control, index) {
        return control.getControlType() == "subgrid";
    });
    
    if (subgrids.length > maxAuto) {
        var subCall = function() {
            var i;
            for (i = maxAuto; i < subgrids.length; i++) {
                var grid = subgrids[i];
                if(grid != null) {
                    grid.refresh();
                }
            }
        };

        window.setTimeout(subCall, loadDelay);
    }
};

And it worked! Not the solution I would like, but I guess that's all I can do now and it also would'n do any harm if something goes wrong.