Hello all. I've begun my journey into writing windows apps to work with our on-prem ifd deployment. We have some orgs on v8.2 and v9. Currently I have a test app that uses the method below retrieve the full name of all records in the contact entity. For now, I'm just interested in exporting the records to an xml file. There will be no record creation, deletion, or updating. I see my results but I have to wonder, is this the correct approach? With the new 'Developer Guide' release, what is deprecated, what isn't deprecated, how do I know which method to use? What are the differences between OrganizationWebProxyClient, OrganizationService, and OrganizationServiceContext? Should I use LINQ, QueryExpression, CreateQuery, FetchXml? So many questions, any help is appreciated.
My test method:
public static void MakeCrmConnection() { List<MyEF6DbSet> lstAllOrgs = new List<MyEF6DbSet>(); lstAllOrgs = GetAllOrgs(); if (lstAllOrgs.Count > 0) { foreach (var MyEF6DbSet in lstAllOrgs) { Console.WriteLine($"Connecting to {MyEF6DbSet.OrganizationName}" + Environment.NewLine); try { CrmServiceClient conn = new CrmServiceClient(getConnString(MyEF6DbSet)); IOrganizationService _orgService = conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; OrganizationServiceContext orgSvcContext = new OrganizationServiceContext(_orgService); if (conn != null && conn.IsReady) { Console.WriteLine($"YAY!!! Connected to {MyEF6DbSet.OrganizationName}" + Environment.NewLine); var query_join = from i in orgSvcContext.CreateQuery("incident") join c in orgSvcContext.CreateQuery("contact") on i["customerid"] equals c["contactid"] select new { contact_name = c["fullname"] }; foreach (var c in query_join) { Console.WriteLine($"Full name is {c.contact_name}"); } } else { Console.WriteLine($"NOT Connected to {MyEF6DbSet.OrganizationName}" + Environment.NewLine); } } catch (Exception) { throw; } } } else { Console.WriteLine("There are no organizations to connect to. Bye."); } }
*This post is locked for comments
Thank you!
You have lots of questions :).
Even e.g. WebAPI is getting more and more popular I think our main tool is Dynamics CRM SDK. it is quick to develop, strong typed etc.. It is our rifle as
Hosk says: https://crmbusiness.wordpress.com/2015/09/16/why-crm-developers-should-always-start-with-the-crm-sdk/.
That means, (in my opinion) most popular methods are Retrieve, RetrieveMultiple. For filtering you use QueryExpression, for definition of what you get use ColumnSet....
I use FetchXML when I can't get what I want with one call of RetrieveMultiple.
From WindowApp I would use Microsoft.Xrm.Tooling.Connector to connect to CRM. .
Using LINQ is popular among some of my colleagues. It is up to your preference.
If I understood well, the sample above could be written as:
CrmServiceClient client = new CrmServiceClient(yourConnectionString);
IOrganizationService service= client;
QueryExpression qe = new QueryExpression("incident");
qe.Criteria.AddCondition(new ConditionExpression("contactid", ConditionOperator.NotNull));
qe.ColumnSet.AddColumn("customerid");
var incidents = service.RetrieveMultiple(qe);
foreach(var inc in incidents.Entities)
{
string fullname = ((EntityReference)(inc["customerid"])).Name;
Console.WriteLine($"Full name is {fullName}");
}
Btw, your code is very similar to one of samples from Microsoft, except here account contacts are retrieved (instead of incident contacts). So you might find good example here (also for getting further fields from Contact entity).
Bump for any other replies, thanks!
Thank you for the suggestion but my process will be automated through code and will trigger to run every 5 minutes. Exporting to excel and converting to xml is way too much manual intervention.
Hi phoeneous,
A better approach to solving this problem is to export the records into an XLS document and then convert the XLS document to an XML document, but you can continue with the custom development approach.
Read these articles to understand the diffference between OrganizationWebProxyClient, OrganizationService, and OrganizationServiceContext.
You can use LINQ, QueryExpression, or FetchXML depending on your personal preference.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156