Hii, i want to retrieve a field value then add into List. I write this following code:
public List<Presid> GetPresalesIdList(string userlogin)
{
List<Presid> idsales = new List<Presid>();
Presid presales = new Presid();
string cmb = userdomain + userlogin;
InitializeCRMService(userName, passWord, domain);
try
{
if (!string.IsNullOrEmpty(userlogin))
{
QueryExpression qe = new QueryExpression("systemuser");
string[] cols = { "businessunitid", "domainname", "systemuserid" };
qe.Criteria = new FilterExpression();
qe.Criteria.AddCondition("domainname", ConditionOperator.Equal, cmb);
qe.ColumnSet = new ColumnSet(cols);
var guid = _service.RetrieveMultiple(qe);
userid = ((EntityReference)guid[0].Attributes["businessunitid"]).Id;
systemid = (Guid)guid[0].Attributes["systemuserid"];
QueryExpression query = new QueryExpression("opportunity");
string[] cols2 = { "new_presalesid", "ownerid" };
query.Criteria = new FilterExpression();
query.Criteria.AddCondition("ownerid", ConditionOperator.Equal, systemid);
query.ColumnSet = new ColumnSet(cols2);
EntityCollection preid = _service.RetrieveMultiple(query);
foreach (Entity enty in preid.Entities)
{
presales.PresalesID = enty.GetAttributeValue<string>("new_presalesid");
idsales.Add(presales);
}
return idsales;
}
}
catch (Exception ex)
{
}
return idsales;
}
But, its give me result :
In other word those result mean that no data has added into List. So i check wether my query get data from CRM or not:
string tes = string.Empty;
foreach (Entity enty in preid.Entities)
{
tes = tes + enty.GetAttributeValue<string>("new_presalesid");
presales.PresalesID = tes;
idsales.Add(presales);
}
By modified my code like above, i know that my query has data in it. The "tes" string show me there are many record. So i think the problem start when i want to add the data one by one into the List. However, i already browse on the internet how to add value into list. And i think there is no mistake with my code. Could somebody tell me the way to fix this ?
This is a WCF Service, so i have data contract like this:
[DataContract]
public class Presid
{
[DataMember]
public string PresalesID
{
get;
set;
}
}