Wednesday 11 July 2012

using Fetch XML to retreive data from dynamic crm

Senario: need to retreive data in C#.net code from dynamic crm 2011.


public Stream SearchCaseByOwner(string owner, bool isAll)
        {
            string query = "<fetch mapping='logical'><entity name='incident'><attribute name='incidentid'/><attribute name='title'/><attribute name='ticketnumber'/><attribute name='customerid'/><attribute name='customeridname'/><attribute name='con_kontaktpersonid'/><attribute name='con_kontaktpersonidname'/><attribute name='con_sagstypeid'/><attribute name='con_sagstypeidname'/><attribute name='con_afregningsform'/><attribute name='con_afregningsformname'/><attribute name='con_sagsstatus'/><order attribute='con_sagsstatus'/><filter type='and'><condition attribute='owneridname' operator='like' value='%{search}%'/></filter></entity></fetch>";
            string result = crmService.Fetch(query.Replace("{search}", owner));
            return ConvertCaseJS(result);
        }


search user:


public Stream SearchUser(string name, string customer)
        {
            return LoadLookup("contact", "yomifullname", "contactid", name, customer);
        }


 public Stream SearchUser(string name,bool isLookup)
        {
            return LoadLookup("contact", "yomifullname","contactid", name, isLookup);
        }


Reading the Lookup id name:
private Entity GetLookup(Customer entLoup)
        {
            if (entLoup == null) return null;
            Entity ent = new Entity();
            ent.Id = entLoup.Value.ToString();
            ent.Name = entLoup.name;
            return ent;
        }

Getting the Current user:
string username = System.Web.HttpContext.Current.User.Identity.Name;


No comments:

Post a Comment