Hi all,
try
{
if (AuthenticateCRM())
{
CrmSdk.BusinessEntityCollection multiretrieved =
GetMultiEntityValues(CrmSdk.EntityName.new_assigncallcenterusers.ToString(), "new_name", sProject, crmService);
if (multiretrieved.BusinessEntities.Length > 0)
{
foreach (CrmSdk.BusinessEntity myProjectEntity in multiretrieved.BusinessEntities)
{
CrmSdk.new_assigncallcenterusers objProject = (CrmSdk.new_assigncallcenterusers)myProjectEntity;
if (objProject.statecode.Value.ToString() == "Active")
{
//Getting LeadCount of the sales resource for a specific project
CrmSdk.ConditionExpression conditionPrincipal =
new CrmSdk.ConditionExpression();
conditionPrincipal.AttributeName = "ownerid";
conditionPrincipal.Operator = CrmSdk.ConditionOperator.Equal;
conditionPrincipal.Values = new object[1];
conditionPrincipal.Values[0] = objProject.new_salesresourceid.Value;
CrmSdk.ConditionExpression conditionPrincipal2 =
new CrmSdk.ConditionExpression();
conditionPrincipal2.AttributeName = "new_callagentid";
conditionPrincipal2.Operator = CrmSdk.ConditionOperator.NotNull;
//conditionPrincipal2.Values = new object[1];
//conditionPrincipal2.Values[0] = sPhoneNo;
CrmSdk.ConditionExpression conditionPrincipal3 =
new CrmSdk.ConditionExpression();
conditionPrincipal3.AttributeName = "new_projectname";
conditionPrincipal3.Operator = CrmSdk.ConditionOperator.Equal;
conditionPrincipal3.Values = new object[1];
conditionPrincipal3.Values[0] = objProject.new_projectid.Value;
CrmSdk.ConditionExpression conditionPrincipal4 =
new CrmSdk.ConditionExpression();
conditionPrincipal4.AttributeName = "createdon";
conditionPrincipal4.Operator = CrmSdk.ConditionOperator.Between;
conditionPrincipal4.Values = new object[2];
conditionPrincipal4.Values[0] = ConvertToCRMDateTime(dtStartDate).Value;
conditionPrincipal4.Values[1] = ConvertToCRMDateTime(dtEndDate).Value;
//CrmSdk.ConditionExpression conditionPrincipal5 =
//new CrmSdk.ConditionExpression();
//conditionPrincipal3.AttributeName = "new_city";
//conditionPrincipal3.Operator = CrmSdk.ConditionOperator.Equal;
//conditionPrincipal3.Values = new object[1];
//conditionPrincipal3.Values[0] = objProject.new_city.Value;
// Create the FilterExpression
CrmSdk.FilterExpression filterPrincipal = new CrmSdk.FilterExpression();
// Set the FilterExpression's Properties
filterPrincipal.FilterOperator = CrmSdk.LogicalOperator.And;
filterPrincipal.Conditions = new CrmSdk.ConditionExpression[] { conditionPrincipal,
conditionPrincipal2, conditionPrincipal3, conditionPrincipal4 };
// Create the Query Expression
CrmSdk.QueryExpression queryPrincipal = new CrmSdk.QueryExpression();
// Set the QueryExpression's Properties
queryPrincipal.EntityName = CrmSdk.EntityName.lead.ToString();
queryPrincipal.ColumnSet = new CrmSdk.AllColumns();//colsPrincipal;;
queryPrincipal.Criteria = filterPrincipal;
/// Retrieve the Lead details.
CrmSdk.BusinessEntityCollection retrieved = crmService.RetrieveMultiple(queryPrincipal);
if (retrieved.BusinessEntities.Length > 0)
{
iCurrUserCount = retrieved.BusinessEntities.Length;
sCurrUser = objProject.new_salesresourceid.name;
}
else
{
iCurrUserCount = 0;
}
if (bFirstUser)
sFirstUser = sCurrUser;
if (iCurrUserCount == 0 && bFirstUser)
{
sSalesResource = objProject.new_salesresourceid.name;
return sSalesResource;
}
else if (iCurrUserCount == 0)
{
sSalesResource = objProject.new_salesresourceid.name;
return sSalesResource;
}
else if (iCurrUserCount > 0 && iPrevUserCount > 0 &&
iCurrUserCount < iPrevUserCount)
{
sSalesResource = objProject.new_salesresourceid.name;
return sSalesResource;
}
//else
//{
sPrevUser = sCurrUser;
iPrevUserCount = iCurrUserCount;
bFirstUser = false;
}
}
}
}
return sFirstUser;
}
catch (SoapException ex)
{
throw new Exception("An error occurred while attempting to authenticate.", ex);
}
}
public static CrmSdk.BusinessEntityCollection GetMultiEntityValues(string sEntity, string sAttribute, string sAttributeValue, CrmSdk.CrmService myCrm)
{
CrmSdk.ConditionExpression conditionPrincipal =
new CrmSdk.ConditionExpression();
conditionPrincipal.AttributeName = sAttribute;
conditionPrincipal.Operator = CrmSdk.ConditionOperator.Equal;
conditionPrincipal.Values = new string[] { sAttributeValue };
CrmSdk.FilterExpression filterPrincipal = new CrmSdk.FilterExpression();
filterPrincipal.FilterOperator = CrmSdk.LogicalOperator.And;
filterPrincipal.Conditions = new CrmSdk.ConditionExpression[] { conditionPrincipal };
CrmSdk.QueryExpression queryPrincipal = new CrmSdk.QueryExpression();
queryPrincipal.EntityName = sEntity;
queryPrincipal.ColumnSet = new CrmSdk.AllColumns();//colsPrincipal;
queryPrincipal.Criteria = filterPrincipal;
/// Retrieve the project details.
CrmSdk.BusinessEntityCollection retrieved = myCrm.RetrieveMultiple(queryPrincipal);
//CrmSdk.BusinessEntity myEntity = (CrmSdk.BusinessEntity)retrieved.BusinessEntities[0];
return retrieved;
}
I need help to write a code to filter record based on 2 fields...
In this line:GetMultiEntityValues(CrmSdk.EntityName.new_assigncallcenterusers.ToString(), "new_name", sProject, crmService);
am filtering records by new_name..i also need to filter records by new_city.
How to do that?
Please help