Answered by:
retrieve dynamic marketing list members

Question
-
Hi,
I use crm 4 web services and can't get members on dynamic marketing lists. Is there any way to go around this?
Wednesday, September 26, 2012 7:53 AM
Answers
-
CrmService oCrmService = new CrmService(); oCrmService.Url = "http://<<CRMSERVER>>:5555/MSCrmServices/2007/CrmService.asmx";//**CHANGE THIS TO YOUR CRM SERVER**// oCrmService.UseDefaultCredentials = true; CrmAuthenticationToken token = new CrmAuthenticationToken(); token.AuthenticationType = 0; token.OrganizationName = "<<CRM ORG NAME>>"; //**CHANGE THIS TO YOUR ORG NAME**// oCrmService.CrmAuthenticationTokenValue = token; //retrieve query related to current marketing list string dynamicMarketingList = "LIST_TEST"; //**CHANGE THIS TO YOUR LIST NAME**// QueryExpression query = new QueryExpression(); query.ColumnSet = new AllColumns(); ConditionExpression listnameCondition = new ConditionExpression(); listnameCondition.AttributeName = "listname"; listnameCondition.Operator = ConditionOperator.Equal; listnameCondition.Values = new String[] { dynamicMarketingList }; FilterExpression filterList = new FilterExpression(); filterList.Conditions.Add(listnameCondition); query.EntityName = "list"; query.Criteria = filterList; // Execute the query RetrieveMultipleRequest req = new RetrieveMultipleRequest(); req.Query = query; req.ReturnDynamicEntities = true; RetrieveMultipleResponse res = (RetrieveMultipleResponse)oCrmService.Execute(req); if (res.BusinessEntityCollection.BusinessEntities.Count > 0) { DynamicEntity myList = (DynamicEntity)res.BusinessEntityCollection.BusinessEntities[0]; if (myList.Properties.Contains("query")) { //Now get fetchXML string fetchXMLQuery = (string)myList["query"]; //Convert fetchXML to Query Expression FetchXmlToQueryExpressionRequest conversationRequest = new FetchXmlToQueryExpressionRequest(); conversationRequest.FetchXml = fetchXMLQuery; FetchXmlToQueryExpressionResponse conversationResponse = (FetchXmlToQueryExpressionResponse)oCrmService.Execute(conversationRequest); //run this fetchXML/query express to to get desired result RetrieveMultipleRequest reqMR = new RetrieveMultipleRequest(); req.Query = conversationResponse.Query; req.ReturnDynamicEntities = false; RetrieveMultipleResponse resMS = (RetrieveMultipleResponse)oCrmService.Execute(req); //now check the count and cast the entity as per your list type (i.e. account, contact ior lead) if (resMS.BusinessEntityCollection.BusinessEntities.Count > 0) { MessageBox.Show("found " + resMS.BusinessEntityCollection.BusinessEntities.Count.ToString() + " records !!"); } } }
above is code for this using CRM 4.0 end points, please study above code and use as per your requirement..
hope this helps..
MayankP
My Blog
Follow Me on Twitter- Marked as answer by R M A C Wednesday, September 26, 2012 11:19 AM
Wednesday, September 26, 2012 9:19 AMAnswerer
All replies
-
Hello,
I believe that the easiest way is to read query of dynamics list and retrieve members using this query.
- Proposed as answer by Mayank PujaraEditor Wednesday, September 26, 2012 8:44 AM
Wednesday, September 26, 2012 8:23 AMModerator -
Andrii is correct, for dynamic marketing list system will store fetch xml in field called query. so you need to retrive this fetchXML and run it to get the marketing list members and use them..
MayankP
My Blog
Follow Me on TwitterWednesday, September 26, 2012 8:48 AMAnswerer -
Thanks,
That is what I found seraching. I have some problem putting it together. Is it possible for you to help me out?
The examples found uses stuff that I don't. Like an organizationcontext and linq. I would like to get it to work with an instance of CrmService.
Wednesday, September 26, 2012 8:49 AM -
Thanks,
That is what I found seraching. I have some problem putting it together. Is it possible for you to help me out?
The examples found uses stuff that I don't. Like an organizationcontext and linq. I would like to get it to work with an instance of CrmService.
So use CRM 2011 endpoints. Why do you want to use CRM 4.0 services?Wednesday, September 26, 2012 8:58 AMModerator -
The call I need to do is to fix a problem in a big solution that only uses 4.0 services.Wednesday, September 26, 2012 9:02 AM
-
The call I need to do is to fix a problem in a big solution that only uses 4.0 services.
In this case you will have to do everything with your own.Wednesday, September 26, 2012 9:12 AMModerator -
CrmService oCrmService = new CrmService(); oCrmService.Url = "http://<<CRMSERVER>>:5555/MSCrmServices/2007/CrmService.asmx";//**CHANGE THIS TO YOUR CRM SERVER**// oCrmService.UseDefaultCredentials = true; CrmAuthenticationToken token = new CrmAuthenticationToken(); token.AuthenticationType = 0; token.OrganizationName = "<<CRM ORG NAME>>"; //**CHANGE THIS TO YOUR ORG NAME**// oCrmService.CrmAuthenticationTokenValue = token; //retrieve query related to current marketing list string dynamicMarketingList = "LIST_TEST"; //**CHANGE THIS TO YOUR LIST NAME**// QueryExpression query = new QueryExpression(); query.ColumnSet = new AllColumns(); ConditionExpression listnameCondition = new ConditionExpression(); listnameCondition.AttributeName = "listname"; listnameCondition.Operator = ConditionOperator.Equal; listnameCondition.Values = new String[] { dynamicMarketingList }; FilterExpression filterList = new FilterExpression(); filterList.Conditions.Add(listnameCondition); query.EntityName = "list"; query.Criteria = filterList; // Execute the query RetrieveMultipleRequest req = new RetrieveMultipleRequest(); req.Query = query; req.ReturnDynamicEntities = true; RetrieveMultipleResponse res = (RetrieveMultipleResponse)oCrmService.Execute(req); if (res.BusinessEntityCollection.BusinessEntities.Count > 0) { DynamicEntity myList = (DynamicEntity)res.BusinessEntityCollection.BusinessEntities[0]; if (myList.Properties.Contains("query")) { //Now get fetchXML string fetchXMLQuery = (string)myList["query"]; //Convert fetchXML to Query Expression FetchXmlToQueryExpressionRequest conversationRequest = new FetchXmlToQueryExpressionRequest(); conversationRequest.FetchXml = fetchXMLQuery; FetchXmlToQueryExpressionResponse conversationResponse = (FetchXmlToQueryExpressionResponse)oCrmService.Execute(conversationRequest); //run this fetchXML/query express to to get desired result RetrieveMultipleRequest reqMR = new RetrieveMultipleRequest(); req.Query = conversationResponse.Query; req.ReturnDynamicEntities = false; RetrieveMultipleResponse resMS = (RetrieveMultipleResponse)oCrmService.Execute(req); //now check the count and cast the entity as per your list type (i.e. account, contact ior lead) if (resMS.BusinessEntityCollection.BusinessEntities.Count > 0) { MessageBox.Show("found " + resMS.BusinessEntityCollection.BusinessEntities.Count.ToString() + " records !!"); } } }
above is code for this using CRM 4.0 end points, please study above code and use as per your requirement..
hope this helps..
MayankP
My Blog
Follow Me on Twitter- Marked as answer by R M A C Wednesday, September 26, 2012 11:19 AM
Wednesday, September 26, 2012 9:19 AMAnswerer