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); }

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...