Showing posts with label Training. Show all posts
Showing posts with label Training. Show all posts

Thursday, February 12, 2009

Example of Dynamic Entity Retrieval

by Danny Varghese 01.31.09


There have been numerous requests on other blogs about sample code to on how to retrieve entities in CRM. One way is to use the CRM web service to retrieve business entities, however by doing so, you're only limited to out-of-the-box entities with system attributes. To retrieve anything more "dynamic," you'll have to employ other methods.  Please remember that in order to retrieve any record, you must have the proper permissions on that entity.

Below is a code example of how to retrieve a record with an id using dynamic entity retrieve:

public DynamicEntity RetrieveEntity()


{


            //variable initialization     


            TargetRetrieveDynamic target = new TargetRetrieveDynamic();         


            RetrieveRequest retrieveRequest = new RetrieveRequest();            


            RetrieveResponse retrieveResponse = null;                                       


            DynamicEntity entity = null;                                      


 


            target.EntityName = <name of entity here>


            target.EntityId = <id of entity here>


 


            //initialize request parameters


            retrieveRequest.ColumnSet = new AllColumns();


            retrieveRequest.ReturnDynamicEntities = true;


            retrieveRequest.Target = target;


 


            //build the response object


            retrieveResponse = (RetrieveResponse)GetCrmService().Execute(retrieveRequest);


 


            //retrieve the service order item from the response


            entity = (DynamicEntity)retrieveResponse.BusinessEntity;


 


            return entity;


}


 




 



The above example is a simple one, but the example below retrieves all contacts that have an account id = some id, and also retrieve the records with only a certain attributes. This is probably a more robust example encompassing many retrieval options:



 





private ArrayList RetrieveMultipleContacts(ICrmService crmService, Guid parentAccountId)


{


    //variable initialization


    ConditionExpression condition = new ConditionBLOCKED EXPRESSION;


    FilterExpression filter = new FilterBLOCKED EXPRESSION;


    QueryExpression query = new QueryBLOCKED EXPRESSION;


    RetrieveMultipleRequest request = new RetrieveMultipleRequest();


    ColumnSet cols = new ColumnSet();


    RetrieveMultipleResponse response = null;


    ArrayList contacts = new ArrayList();


 


    //Set the condition for retrieval


    condition.AttributeName = "parentcustomerid";


    condition.Operator = ConditionOperator.Equal;


    condition.Values = new string[] { parentAccountId.ToString() };


 


     //Set the properties of the filter.


    filter.FilterOperator = LogicalOperator.And;


    filter.AddCondition(condition);


 


    //Set the attributes needed to be returned.  NOTE: The CRM Sdk has an erroneous example


    //of how to set the attributes for retrieval. 


    cols.Attributes.Add("address1_line1");


    cols.Attributes.Add("address1_line2");


    cols.Attributes.Add("address1_line3");


    cols.Attributes.Add("address1_city");


    cols.Attributes.Add("address1_stateorprovince");


    cols.Attributes.Add("address1_postalcode");


    cols.Attributes.Add("address1_country");


    cols.Attributes.Add("telephone1");


    cols.Attributes.Add("fax");


 


    //Set the properties of the QueryExpression object.


    query.EntityName = EntityName.contact.ToString();


    query.ColumnSet = cols;


    query.Criteria = filter;


 


    //Set the query for the request and set the flag to return


    //dynamic entities


    request.Query = query;


 


    //retrieve the contacts


    response = (RetrieveMultipleResponse)crmService.Execute(request);


    foreach (BusinessEntity cont in response.BusinessEntityCollection.BusinessEntities)


    {


        contacts.Add(cont);


    }


 


    return contacts;


}



I hope these examples help someone, happy coding!

Tuesday, August 5, 2008

Microsoft Dynamics CRM 4.0: Star-Casts (*Casts)

Posted: Saturday, January 26, 2008 1:04 PM by Sanjay Jain

Enjoy the following collection of various Microsoft Dynamics CRM 4.0 casts produced by me and my colleagues at Microsoft. We would welcome your feedback and suggestions for future ones.

Last Updated: 02/25/2008

Changes: Added 3 new  

Count:

·         Pod-Casts: 1

·         Video-Casts/Web-Casts: 4

·         Screen-Casts: 24 (Planning – 9; Installing – 10; Operating – 5)

 

Microsoft Dynamics CRM 4.0 Pod-Casts

Icon

Description

Author

What's New: CTO Campus Management Corp on Microsoft Dynamics Build/Buy Partner

Sanjay Jain

 

Microsoft Dynamics CRM 4.0 Video-Casts/Web-Casts

Tags

Description

Author

Overview

CRM 4.0 Overview

Philip Richardson

Platform

CRM 4.0 Deep Dive

Philip Richardson

Report

CRM 4.0 Reporting with Barry Givens and Phil Richardson

Philip Richardson

Barry Givens

Workflow

CRM 4.0 Workflow with Praveen Upadhyay

Ben Riga

Praveen Upadhyay

 

Microsoft Dynamics CRM 4.0 Screen-Casts

Tags

Description

Author

Planning

Multi Language

Multi Lingual

Philip Richardson

MUI, Multi Language

Microsoft Dynamics CRM 4.0 Multi-Language User Interface (MUI) with Sanjay Jain

Sanjay Jain

Multi Currency

Microsoft Dynamics CRM 4.0 Multi-Currency with Sanjay Jain

Sanjay Jain

Data Migration

Microsoft Dynamics CRM 4.0 : Data Migration Manager with John O'Donnell

John O’Donnell

Data Migration

Data Migration

Philip Richardson

Data Import

Web Import

Philip Richardson

De-Dup

Duplicate Detection

Philip Richardson

Relationship

Many to Many Relationships

Philip Richardson

Relationship

Many to Many Relationships

Humberto Lezama Guadarrama

Installing

Installation

Install CRM

Philip Richardson

Installation

Microsoft Dynamics CRM 4.0 : Installation with John O'Donnell

John O’Donnell

OCS

Microsoft Dynamics CRM 4.0 Office Communication Server 2007 with Sanjay Jain

Sanjay Jain

Outlook

CRM for Outlook

Philip Richardson

Outlook

Configuring the Outlook Client for CRM 4.0

Philip Richardson

Users

Add Multiple Users

Philip Richardson

Configure

Navigation Areas Configuration

Humberto Lezama Guadarrama

E-Mail Router

The CRM 4.0 E-mail Router with POP3

Michael Lu

E-Mail Router

CRM 4.0 E-mail Router with a Forward Mailbox

Michael Lu

E-Mail Router

CRM 4.0 E-mail Router with Exchange

Michael Lu

Operating

Report Wizard

Microsoft Dynamics CRM 4.0 : Report Wizard with John O'Donnell

John O’Donnell

Workflow

Workflow: Basic

Philip Richardson

Workflow

Workflow: Complex

Philip Richardson

Workflow

Workflow: Activity

Philip Richardson

Mail Merge

Mail Merge

Michael Lu

 

Disclaimers:

·         These casts are produced on various versions of the product including pre-release versions, so may not reflect the latest behavior of the product.

·         Provided “AS-IS”

 

Sanjay Jain

Microsoft Dynamics ISV Architect Evangelist