Previous Thread

8/18/2006 11:00:01 AM    CRM 3.0 SDK
Hi 
 
I saw sample code in the CRM 3.0 SDk. 
 
// ===================================================================== 
 
//  File:		Retrieve.cs 
 
//  Summary:	This sample shows how to retrieve an account by accountid 
 
//              using Execute and RetrieveRequest. 
 
// ===================================================================== 
 
// 
 
//  This file is part of the Microsoft CRM 3.0 SDK Code Samples. 
 
// 
 
//  Copyright (C) Microsoft Corporation.  All rights reserved. 
 
// 
 
//  This source code is intended only as a supplement to Microsoft 
 
//  Development Tools and/or on-line documentation.  See these other 
 
//  materials for detailed information regarding Microsoft code samples. 
 
// 
 
//  THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
 
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
 
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
 
//  PARTICULAR PURPOSE. 
 
// 
 
// ===================================================================== 
 
using System; 
 
using CrmSdk; 
 
namespace Microsoft.Crm.Sdk.Reference.CrmServiceApi.Common 
 
{ 
 
/// <summary> 
 
/// This sample shows how to retrieve an account by accountid using Execute 
 
and RetrieveRequest. 
 
/// </summary> 
 
public class Retrieve 
 
{ 
 
public Retrieve() 
 
{ 
 
} 
 
public static bool Run() 
 
{ 
 
// Set up the CRM Service. 
 
CrmService service = new CrmService(); 
 
service.Credentials = System.Net.CredentialCache.DefaultCredentials; 
 
account account = new account(); 
 
account.name = "Fourth Coffee"; 
 
TargetCreateAccount targetCreate = new TargetCreateAccount(); 
 
targetCreate.Account = account; 
 
CreateRequest create = new CreateRequest(); 
 
create.Target = targetCreate; 
 
CreateResponse created = (CreateResponse) service.Execute(create); 
 
// Create the column set object that indicates the fields to be retrieved. 
 
ColumnSet cols = new ColumnSet(); 
 
// Set the properties of the column set. 
 
cols.Attributes = new string [] {"name"}; 
 
// Create the target object for the request. 
 
TargetRetrieveAccount target = new TargetRetrieveAccount(); 
 
// Set the properties of the target object. 
 
// EntityId is the GUID of the record being retrieved. 
 
// SDK: target.EntityId = new Guid("2B951FBC-1C56-4430-B23B-20A1349068F3"); 
 
target.EntityId = created.id; 
 
// Create the request object. 
 
RetrieveRequest retrieve = new RetrieveRequest(); 
 
// Set the properties of the request object. 
 
retrieve.Target = target; 
 
retrieve.ColumnSet = cols; 
 
// Execute the request. 
 
RetrieveResponse retrieved = (RetrieveResponse)service.Execute(retrieve); 
 
bool success = false; 
 
if (retrieved.BusinessEntity != null) 
 
{ 
 
success =  true; 
 
} 
 
TargetDeleteAccount targetDelete = new TargetDeleteAccount(); 
 
targetDelete.EntityId = created.id; 
 
DeleteRequest delete = new DeleteRequest(); 
 
delete.Target = targetDelete; 
 
service.Execute(delete); 
 
return success; 
 
} 
 
} 
 
} 
 
In this short C# program, the developer first creates a CRM account then he 
 
updates it. I wanted to know, how can I obtain the accountId for an existing 
 
CRM account which I want to update. Is there a method I can call to retrieve 
 
just the GUID of the account so that I can update it.



8/18/2006 9:14:59 PM    Re: CRM 3.0 SDK
You need to search for it. This is done by using QueryExpression or 
 
QueryByAttribute and a call to RetrieveMultiple. Look at 
 
http://www.stunnware.com/crm2/topic.aspx?id=FindingData1 for a quick 
 
introduction. 
 
-- 
 
Michael 
 
http://www.stunnware.com/crm2 
 
---------------------------------------------------------- 
 
"nitadmin" <nitadmin@discussions.microsoft.com> schrieb im Newsbeitrag 
 
news:660FB867-702E-41DD-8B73-92319EEE6A4A@microsoft.com...