Wednesday, September 24, 2008

Check Number of notes attached to a Crm Record.


Write below code on save of the entity.

var CRM_FORM_TYPE_CREATE = 1;
 
if (crmForm.FormType == CRM_FORM_TYPE_CREATE)
{
    var obj=document.frames(”notescontrol”).document;
    var textarea=obj.getElementsByTagName(’TEXTAREA’);
 
    if (textarea.length < 1)
    {
        alert (”please eneter somenotes”);
 
        // Cancel the save
        event.returnValue = false;
    }
}

CRM Form Types


Is the user creating a new record?
crmForm.FormType == 1

Is the user updating an existing record
crmForm.FormType ==2

Is the user unable to update this record?
crmForm.FormType == 3

Is this record deactivated?
crmForm.FormType == 4

Is the user using the Quick Create form?
crmForm.FormType == 5

Is the user using the Bulk Edit form?
crmForm.FormType == 6

What is the unique ID for this record?
= crmForm.ObjectId

What type of record is this?
= crmForm.ObjectTypeCode

What type of record is this (Entity Name)?
= crmForm.ObjectTypeName

Is the user using the Outlook Client?
crmForm.IsForOutlookClient==true

Is the user using the Outlook Light Client?
crmForm.IsForOutlookLightClient == true

Is the user working On line?
crmForm.IsOnline==true

Have any fields in this form been changed?
crmForm.IsDirty==true

Hide all Tabs on CRM Form



//Below is the javascript code, which will hide all tabs on CRM form.
document.getElementById("crmTabBar").style.display = "none";


//If you want to hide a specific tab, use below code:
document.getElementById("tab0Tab").style.display = "none";


//Here "tab0Tab" is first tab on the Crm Form.

Tuesday, September 23, 2008

How to attach onClose event to MS CRM Entity.


When you work with CRM Forms, if you want to capture / attach a onClose() Event, just use below javascript code.

window.onunload = function() {
//add code here
}

Delete / DisAssociate Many to Many Relationship Record.


When you say DisAssocaiating a Many to Many Relationship Record, then you usually deattach the record, you won't delete the record.

Below function will DisAssocaiate a record. Here, you need to pass three parameter values
Parent Entity Guid,
Child Entity Guid, and
Relationship Name.

public bool DisassociateManyToManyEntityRecords(Moniker Moniker1, Moniker Moniker2, string strEntityRelationshipName)
{
try
{
// Create a request.
DisassociateEntitiesRequest request = new DisassociateEntitiesRequest();

        // Assign the request a moniker for both entities that need to be disassociated.
request.Moniker1 = Moniker1;
request.Moniker2 = Moniker2;

        // Set the relationship name that associates the two entities.
request.RelationshipName = strEntityRelationshipName.Trim();
        // Execute the request.
DisassociateEntitiesResponse response = (DisassociateEntitiesResponse)Service.Execute(request);

        return true;
}

    catch (SoapException ex)
{
return false;
}
}