Thursday, September 29, 2011

Using Fetch Expression from the Plug in code. CRM 2011

Fallowing, are the steps that we can make use of while executing the Fetch XML query.

1) Create a fetch xml query with the help of Advanced find option and format as in the below code

2) Call service.RetrieveMultiple and pass on the Fetch Xml query to the Fetch expression as in the below code. This should give you the result.

string fetchAccountType = @""+
""+ 
       ""+
       ""+
       ""+
       ""+
       ""+
       ""+
       ""+
       ""+
       ""+
       //Passsing a parameter (accountId) to the fetch xml query
       "" +
       ""+
       ""+
       ""+
       ""+
       "";
                var entityCollection = service.RetrieveMultiple(new FetchExpression(fetchAccountType));
                string accountType = string.Empty;
                if (entityCollection.Entities.Count > 0)
                    if (entityCollection.Entities[0].Attributes.Contains("new_name"))
                        accountType = entityCollection.Entities[0].Attributes["new_name"].ToString();     

No comments: