public CRMContact GetContact(string email) { if (CRMConnection != null) { connectCRM(); } string fetchXML = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' returntotalrecordcount='true' > <entity name='contact'> <attribute name='contactid' /> <attribute name='fullname' /> <attribute name='emailaddress1' /> <filter type = 'and'> <condition attribute = 'emailaddress1' value = " + email + @" operator = 'eq' /> </filter> </entity> </fetch>"; EntityCollection collection = Dynamics365Helper.RetrieveXML(fetchXML); CRMContact contact = null; if (collection.Entities != null) { var entity = collection.Entities.FirstOrDefault(); contact = new CRMContact(); contact.Email = entity.Attributes["emailaddress1"].ToString(); contact.FullName = entity.Attributes["fullname"].ToString(); contact.ContactId = new Guid(entity.Attributes["contactid"].ToString()); } return(contact); }
public List <CRMKnowledgeBaseArticle> SearchKB(string keyword) { if (CRMConnection != null) { connectCRM(); } string fetchXML = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' returntotalrecordcount='true' > <entity name='knowledgearticle'> <attribute name='knowledgearticleid' /> <attribute name='modifiedon' /> <attribute name='title' /> <attribute name='description'/> <attribute name='articlepublicnumber'/> <filter type = 'and'> <condition attribute = 'statuscode' value = '7' operator = 'eq' /> <condition attribute = 'keywords' value = '%" + keyword + @"%' operator = 'like' /> </filter> </entity> </fetch>"; EntityCollection collection = Dynamics365Helper.RetrieveXML(fetchXML); List <CRMKnowledgeBaseArticle> kbaList = new List <CRMKnowledgeBaseArticle>(); if (collection != null && collection.Entities != null) { if (collection.Entities.Count > 0) { foreach (Entity e in collection.Entities) { CRMKnowledgeBaseArticle kba = null; if (collection.Entities != null) { kba = new CRMKnowledgeBaseArticle(); kba.title = e.Attributes["title"].ToString(); kba.description = e.Attributes["description"].ToString(); kba.articleNumber = e.Attributes["articlepublicnumber"].ToString(); kba.publishedDate = DateTime.Parse(e.Attributes["modifiedon"].ToString()); } kbaList.Add(kba); } } } return(kbaList); }