Hi,
I am investigating how the duplicate detection rules are working in CRM for an assignment, so far i understand the below points and need help in understanding additional details.
1. Everytime when you create a duplicate detection rule a record is created in duplicaterule entity.It Contains the details of Base entity,matching entity and matchcodetable etc.
2. The details of the attribues on which the rule was made are stored in duplicaterulecondition, so it may contain multiple record for each rule storing the attribue details and the condition.
3. The matchcodetable contains the matchcodes for each of the entity record using the above duplicate rule.
So far everything is fine for me, but i didnt understand how the order of the fields are used to generate matchcodes.
For example: i have created a rule saying firstname and lastname exact match.
For the record,
Firstname : jeevan
lastname: balija
middlename: kumar
city: hyd
it created a matchcode as "balija[sep]jeevan"
Then i modified it to add middlename also at the end of the rule, it updated the matchcode as
"kumar[sep]jeevan[sep]balija"
added one more field city to the rule, then it updated the matchcode as
"kumar[sep]jeevan[sep]balija[sep]hyd"
So it is difficult to understand how the order of the fields are used.
I am trying to use this built in matchcode logic for our custom import project to avoid duplicates.
Any ideas,please post a comment.
Friday, July 29, 2011
Code snippets for future Reference
Hi,
Below are some of the code snippets for CRM 2011, i wanted to write in my blog for future reference or if someone needs they can also refer.
Below are some of the commonly used JavaScript code snippets. I have taken them from this blog
Get the value from a CRM field
var varMyValue = Xrm.Page.getAttribute(“CRMFieldSchemaName”).getValue() ;
Set the value of a CRM field
Xrm.Page.getAttribute(“CRMFieldSchemaName”).setValue(‘My New Value’);
Hide/Show a tab/section
Xrm.Page.ui.tabs.get(5).SetVisible(false);
Xrm.Page.ui.tabs.get(5).SetVisible(true);
Call the onchange event of a field
Xrm.Page.getAttribute(“CRMFieldSchemaName”).fireOnChange();
Get the selected value of picklist
Xrm.Page.getAttribute(“CRMFieldSchemaName”).getSelectedOption().text;
Set the requirement level
Xrm.Page.getAttribute(“CRMFieldSchemaName”).setRequiredLevel(“none”);
Xrm.Page.getAttribute(“CRMFieldSchemaName”).setRequiredLevel(“required”);
Xrm.Page.getAttribute(“CRMFieldSchemaName”).setRequiredLevel(“recommended”);
Set the focus to a field
Xrm.Page.getControl(“CRMFieldSchemaName”).setFocus(true);
Stop an on save event
event.returnValue = false;
Return array of strings of users security role GUIDs:
Xrm.Page.context.getUserRoles()
Hide/Show Tabs and Sections
Code to check whether the currently logged in User is a System Administrator
Below are some of the code snippets for CRM 2011, i wanted to write in my blog for future reference or if someone needs they can also refer.
Below are some of the commonly used JavaScript code snippets. I have taken them from this blog
Get the value from a CRM field
var varMyValue = Xrm.Page.getAttribute(“CRMFieldSchemaName”).getValue() ;
Set the value of a CRM field
Xrm.Page.getAttribute(“CRMFieldSchemaName”).setValue(‘My New Value’);
Hide/Show a tab/section
Xrm.Page.ui.tabs.get(5).SetVisible(false);
Xrm.Page.ui.tabs.get(5).SetVisible(true);
Call the onchange event of a field
Xrm.Page.getAttribute(“CRMFieldSchemaName”).fireOnChange();
Get the selected value of picklist
Xrm.Page.getAttribute(“CRMFieldSchemaName”).getSelectedOption().text;
Set the requirement level
Xrm.Page.getAttribute(“CRMFieldSchemaName”).setRequiredLevel(“none”);
Xrm.Page.getAttribute(“CRMFieldSchemaName”).setRequiredLevel(“required”);
Xrm.Page.getAttribute(“CRMFieldSchemaName”).setRequiredLevel(“recommended”);
Set the focus to a field
Xrm.Page.getControl(“CRMFieldSchemaName”).setFocus(true);
Stop an on save event
event.returnValue = false;
Return array of strings of users security role GUIDs:
Xrm.Page.context.getUserRoles()
Hide/Show Tabs and Sections
function setVisibleTabSection(tabname, sectionname, show) {
var tab = Xrm.Page.ui.tabs.get(tabname);
if (tab != null) {
if (sectionname == null)
tab.setVisible(show);
else {
var section = tab.sections.get(sectionname);
if (section != null) {
section.setVisible(show);
if (show)
tab.setVisible(show);
}
}
}
}
Code to check whether the currently logged in User is a System Administrator
if (typeof (SDK) == "undefined")
{ SDK = {}; }
// Create Namespace container for functions in this library;
SDK.ContextSamples = {
isUserSysAdmin: function ()
{
var serverUrl = Xrm.Page.context.getServerUrl();
var query = "/XRMServices/2011/OrganizationData.svc/RoleSet?$top=1&$filter=Name eq
'System Administrator'&$select=RoleId";
var retrieveRoleRequest = new XMLHttpRequest();
retrieveRoleRequest.open("GET", serverUrl + query, true);
retrieveRoleRequest.onreadystatechange = function ()
{
SDK.ContextSamples.retrieveRoleResponse(this);
};
retrieveRoleRequest.send();
},
retrieveRoleResponse: function (retrieveRoleRequest)
{
if (retrieveRoleRequest.readyState == 4)
{
if (retrieveRoleRequest.status == 200)
{
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0")
xmlDoc.async = false;
xmlDoc.loadXML(retrieveRoleRequest.responseText);
var sysAdminRoleId = xmlDoc.selectSingleNode("//*[local-name() =
'RoleId']").text
var currentUserRoles = Xrm.Page.context.getUserRoles();
for (var i = 0; i < currentUserRoles.length; i++)
{
var userRole = currentUserRoles[i];
if (userRole == sysAdminRoleId)
{
alert("The current user has the 'System Administrator' role.");
return;
}
}
alert("The current user does not have the 'System Administrator' role.");
}
else
{
//handle error
alert("Error retrieving user Roles");
}
}
},
};
Wednesday, July 27, 2011
Setting a Lookup value using JavaScript
Below is a sample code for setting the value of a lookup using Javascript in CRM 2011.
It also shows what code change has happened from CRM 4.0
I found this code sample from this blog link
It also shows what code change has happened from CRM 4.0
I found this code sample from this blog link
CRM 4
var value = new Array();
value[0] = new Object();
value[0].id = idValue;
value[0].name = textValue;
value[0].typename = typeValue;
crmForm.all.fieldName.DataValue = value;
CRM 2011
var value = new Array();
value[0] = new Object();
value[0].id = idValue;
value[0].name = textValue;
value[0].entityType = typeValue;
Xrm.Page.getAttribute(“fieldName”).setValue(value);
How about doing it on one line like this instead.
CRM 4
crmForm.all.field.DataValue = [{id: idValue, name: textValue, typename: typeValue}];
CRM 2011
Xrm.Page.getAttribute(“fieldName”).setValue( [{id: idValue, name: textValue, entityType: typeValue}]);
Tuesday, July 19, 2011
Auto number Generation for custom entity in CRM 4.0
The below code can be used for generating auto numbers for CRM 4.0 entities.
I have used project as the sample entity.
I have used project as the sample entity.
public void Execute(IPluginExecutionContext context)
{
DynamicEntity entity = null;
// Check whether the input parameters property bag contains a target
// of the create operation and that target is of type DynamicEntity.
if (context.InputParameters.Properties.Contains("Target") && context.InputParameters.Properties["Target"] is DynamicEntity)
{
// Obtain the target business entity from the input parmameters.
entity = (DynamicEntity)context.InputParameters.Properties["Target"];
// Verify that the entity represents an account.
if (entity.Name != "new_project") { return; }
}
else
{
return;
}
//Query for the max ref number
ICrmService service = context.CreateCrmService(true);
QueryExpression qe = new QueryExpression();
qe.EntityName = "new_project";
ColumnSet cols = new ColumnSet();
cols.Attributes.AddRange(new string[] { "new_projrefnumber" });
qe.PageInfo = new PagingInfo();
qe.PageInfo.Count = 1;
qe.PageInfo.PageNumber = 1;
OrderExpression order = new OrderExpression();
order.AttributeName = "new_projrefnumber";
order.OrderType = OrderType.Descending;
qe.Orders.AddRange(new OrderExpression[] { order });
RetrieveMultipleRequest req = new RetrieveMultipleRequest();
req.ReturnDynamicEntities = true;
req.Query = qe;
//BusinessEntityCollection entityCol = service.RetrieveMultiple(qe);
RetrieveMultipleResponse resp = (RetrieveMultipleResponse)service.Execute(req);
// find the existing max Ref number from the project entity, increment it and update it to the properties.
foreach (BusinessEntity be in resp.BusinessEntityCollection.BusinessEntities)
{
DynamicEntity proj = (DynamicEntity)be;
if (proj.Properties.Contains("new_projrefnumber"))
{
if (proj["new_projrefnumber"] != null)
{
string currentRefNumber = proj["new_projrefnumber"].ToString();
int refNumber = Convert.ToInt32(currentRefNumber) + 1;
if (entity.Properties.Contains("new_projrefnumber"))
{
entity.Properties["new_projrefnumber"] = refNumber.ToString();
}
else
{
entity.Properties.Add(new StringProperty("new_projrefnumber", refNumber.ToString()));
}
}
}
}
}
}
Subscribe to:
Posts (Atom)