Hi All,
I need to create a plugin to prevent the duplication but with a different Criteria The scenario :
I have Maintenance department and service department so fro example :
Contract_number Department
1002 Maintenance
1002 Service
This is right
Contract_number Department
1002 Maintenance
1002 Maintenance
This is wrong
So the following code will prevent the duplication for all contract numbers how can i convert it to be for the departments level The Code:
if (contract.Contains("new_name")) contractNumber = (string)contract.Attributes["new_name"]; else if (contractImg.Contains("new_name")) contractNumber = (string)contractImg.Attributes["new_name"]; QueryExpression qExp = new QueryExpression(); EntityCollection eCol = new EntityCollection(); qExp.EntityName = "new_contract"; qExp.ColumnSet = new ColumnSet("new_name"); qExp.Criteria.AddCondition("new_name", Microsoft.Xrm.Sdk.Query.ConditionOperator.Equal,(contractNumber)); eCol = service.RetrieveMultiple(qExp); if (eCol.Entities.Count > 1) { throw new InvalidPluginExecutionException("Contract Number already exists "); }