Wednesday, July 31, 2013

CRM 2011 Views – Retrieve more than 5000 records

As you probably know, by default CRM view retrieve only 5000 records for the view, to retrieve more than 5000 records we can use following method, Note that this is an unsupported change. This will applied to all Organizations in the CRM.

Database: MSCRM_CONFIG
IntColumn Value: Set to -1,

This will retrieve all records in the table.
UPDATE DeploymentProperties
SET IntColumn = '-1'
WHERE ColumnName = 'TotalRecordCountLimit'
After executing this query give a IIS Reset.

There is another way to change the registry value, But it will only applied to fetch XML, after you changed registry value still you receive only 5000 record in Entity grid. http://www.interactivewebs.com/blog/index.php/server-tips/turn-off-microsoft-crm-2011-5000-limit-on-data-retrieval-via-sdk/

Tuesday, July 30, 2013

NRIC(Singapore) Validation using Javascript

function IsValidNRIC(theNric) {
    var nric = [];
    nric.multiples = [2, 7, 6, 5, 4, 3, 2];

    if (theNric.length != 9) {
        alert('Invalid NRIC')
        return false;
    }

    var total = 0, count = 0, numericNric;
    var first = theNric.charAt(0), last = theNric.charAt(theNric.length - 1);

    if (first != 'S' && first != 's') {
        alert('Invalid NRIC S');
        return false;
    }
    /*Above is working*/

    numericNric = theNric.substr(1, theNric.length - 2);

    if (isNaN(numericNric)) {
        alert('Invalid NRIC Middle Not a number')
        return false
    }

    if (numericNric != null) {
        while (numericNric != 0) {
            total += (numericNric % 10) * nric.multiples[nric.multiples.length - (1 + count++)];
            numericNric /= 10;
            numericNric = Math.floor(numericNric);
        }
    }

    var outputs;
    if (first == 'S') {
        outputs = ['J', 'Z', 'I', 'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A'];
    }

    if (first == 'T') {
        outputs = ['G', 'F', 'E', 'D', 'C', 'B', 'A', 'J', 'Z', 'I', 'H'];
    }

    if (last != outputs[total % 11]) {
        alert('Invalid end Character')
        return false;
    }

    nric.isNricValid = function (theNric) {
        if (!theNric || theNric == '') {
            return false;
        }
    }
    return true;
}

CRM 2011 - Javascript samples

//FIELDS - Values
// Get Text Value
Xrm.Page.getAttribute("feildName").getText();
//Get Picklist Value
Xrm.Page.getAttribute("FieldName").getValue();
//  Set Value
Xrm.Page.getAttribute("FieldName").setValue(newValue);

//GENERAL
// Get Form Type
Xrm.Page.ui.getFormType();
//Get Record Id
Xrm.Page.data.entity.getId();
//Prevent Saving
ExecutionObj.getEventArgs().preventDefault();
//Get user Id
Xrm.Page.context.getUserId();
// Force Submit
Xrm.Page.getAttribute("FieldName").setSubmitMode("always");
//Set Required Level
Xrm.Page.getAttribute("FieldName").setRequiredLevel("none");
Xrm.Page.getAttribute("FieldName").setRequiredLevel("required");
Xrm.Page.getAttribute("FieldName").setRequiredLevel("recommended");
//Get Server Url
var context = Xrm.Page.context;
var serverUrl = context.getServerUrl();

//IFRMAE
//Set IFrams url 
Xrm.Page.getControl("IFRAME_Name").setSrc(URL_IFRAME_CALLSCRIPT);


//SHOW/HIDE/DISABLE
// Disable Field 
Xrm.Page.getControl("FieldName").setDisabled(true);
//Hide Field
Xrm.Page.ui.controls.get("FieldName").setVisible(false);
//Hite Section
Xrm.Page.ui.tabs.get("TabNumber").sections.get('SectionName').setVisible(flag);
//Hide Tab
Xrm.Page.ui.tabs.get("TabNumber").setVisible(false);
//Tab Expand
Xrm.Page.ui.tabs.get(1).setDisplayState("expanded");
Xrm.Page.ui.tabs.get(1).setDisplayState("collapsed");

//PICKLIST
// Get Selecte Text from picklist
Xrm.Page.getAttribute("FieldName").getSelectedOption().text;
//Remove Option from Picklist
Xrm.Page.getControl("FieldName").removeOption(3);
//Add Option to Picklist
function AddOption(value, text, index) {
    var option = new Option(); option.text = text; option.value = value; typeControl.addOption(option, index);
}

//LOOKUP
//Populate Lookup
function PopulateTemplateLookup(recordid, recordName) {
    Xrm.Page.getAttribute("lookupId").setValue([{ id: recordid, name: recordName, entityType: "EntityName"}]);
}
//Get/Check Lookup Values
var lookupObject = Xrm.Page.getAttribute("lookupfield");
if (lookupObject != null) {
    var lookUpObjectValue = lookupObject.getValue();
    if ((lookUpObjectValue != null)) {
        var lookuptextvalue = lookUpObjectValue[0].name;
        var plookupid = lookUpObjectValue[0].id;
    }
}

//Disable Form Fields
function doesControlHaveAttribute(control) {
    var controlType = control.getControlType();
    return controlType != "iframe" && controlType != "webresource" && controlType != "subgrid";
}

function disableFormFields(onOff) {

    Xrm.Page.ui.controls.forEach(function (control, index) {
        if (doesControlHaveAttribute(control)) {
            control.setDisabled(onOff);
        }
    });
}

//Set Email To [Party List]
function setToPartyList() {
        var partlistData = new Array();
        partlistData[0] = new Object();
        partlistData[0].id = '{08C6AFB3-9673-E011-8720-00155DA5304E}'; // userId
        partlistData[0].name = 'Jill Frank'; //user name
        partlistData[0].entityType = 'systemuser'; // Entity name
        Xrm.Page.getAttribute("to").setValue(partlistData);
    }
MSDN Reference :http://msdn.microsoft.com/en-us/library/jj602964.aspx

Tuesday, July 23, 2013

CRM 2011 Add/Remove user from Team

Code snippet :  

public void AddUserToTeam(Guid userid, Guid TeamId) { AddMembersTeamRequest req = new AddMembersTeamRequest(); req.TeamId = TeamId; Guid[] aryMembers = new Guid[1]; aryMembers[0] = userid; req.MemberIds = aryMembers; AddMembersTeamResponse resp = (AddMembersTeamResponse)service.Execute(req); } public void RemoveUserFromTeam(Guid userid, Guid TeamId) { RemoveMembersTeamRequest removeRequest = new RemoveMembersTeamRequest(); removeRequest.TeamId = TeamId; Guid[] aryMembers = new Guid[1]; aryMembers[0] = userid; removeRequest.MemberIds = aryMembers; service.Execute(removeRequest); }

Tuesday, June 25, 2013

Unable to start debugging. The Silverlight Developer Runtime is not installed. Please install a matching version.

Today I tried to run Silverlight sample project in my machine and I got below error.
“Unable to start debugging. The Silverlight Developer Runtime is not installed. Please install a matching version.”

I checked the Silverlight version I installed and it was version 4. Then I just did a Google search and found the below blog post, after installing Silverlight_Developer.exe I was able to run Sample Silverlight application successfully. 



Thanks

Monday, June 24, 2013

CRM 2011 Filtered sub grid

Filtered sub grid is very commonly used feature in CRM 2011.
As you may already know we can use CRM default feature to filter sub grid data by selecting different views for sub grid. But you may come across situations where system needs to filter sub grid data based on opening record field,
For example you need to filter Contact sub grid based on Account form City field. So sub grid should only Contacts which have same city as Account City:
In this kind of scenario we can use javascript to add filter to the sub grid.

Use advance find and generate fetch xml for filter contact

function setContactSubGrid() {
    var grid = $('#accountContactsGrid')[0];
    var accountCity = Xrm.Page.getAttribute("address1_city").getValue();
    if (grid == null || grid.readyState != "complete") {
        setTimeout('setContactSubGrid()', 2000);
    }
    else {

        var fetchXml = "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "";
            
        grid.control.setParameter("fetchXml", fetchXml);

        grid.control.refresh();
    }
}
Call this function on Account onLoad event.

Sunday, June 23, 2013

How to Refresh a SubGrid in MS CRM 2011

Code snippet 1 :

function LoadSubGrid(SubGridName) {
    var grid = document.getElementById(SubGridName);
    if (grid) {
        if (grid.readyState == "complete") {
            grid.Refresh();
        }
    }
}
Code snippet 2 :

function LoadSubGrid(SubGridName) {
    var grid = Xrm.Page.ui.controls.get("SubGridName")
    if (grid) {
        if (grid.readyState == "complete") {
            grid.Refresh();
        }
    }
}

MS CRM 2011 KB Article customization Issue.

Recently I have encountered some issue while customizing Kb Article Entity. I was doing following configuration in Article form. 1. Add Ba...