Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Not recognising WhoAmIResponse and RetrieveRecordChangeHistoryRequest in API

Posted on by 435

Hi Friends , 

I am writing a code to get the orgId and retriveRecord of audit

Guid orgId = ((WhoAmIResponse)_service.Execute(new WhoAmIRequest())).OrganizationId;

RetrieveRecordChangeHistoryRequest changeRequest = new RetrieveRecordChangeHistoryRequest();

but my API not recognising  WhoAmIResponse, RetrieveRecordChangeHistoryRequest

I am using CRM 2015 on line  and VS 2012.

//******************************************************************

//<snippetAuditing>
using System;
using System.ServiceModel;
using System.Collections.Generic;
using System.Linq;

// These namespaces are found in the Microsoft.Xrm.Sdk.dll assembly
// located in the SDK\bin folder of the SDK download.
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;

// These namespaces are found in the Microsoft.Crm.Sdk.Proxy.dll assembly
// located in the SDK\bin folder of the SDK download.


namespace Microsoft.Crm.Sdk.Samples
{
public class Auditing
{
#region Class Level Members

private OrganizationServiceProxy _serviceProxy;
private IOrganizationService _service;

private Guid _newAccountId;

#endregion Class Level Members

#region How To Sample Code
/// <summary>
/// This method first connects to the organization service. Next, auditing
/// is enabled on the organization and an account entity. The account record
/// is updated and the audit history printed out.
/// </summary>
/// <param name="serverConfig">Contains server connection information.</param>
/// <param name="promptforDelete">When True, the user will be prompted to delete all
/// created entities.</param>
public void Run(ServerConnection.Configuration serverConfig, bool promptforDelete)
{
using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri, serverConfig.Credentials, serverConfig.DeviceCredentials))
{
// Enable early-bound type support.
_serviceProxy.EnableProxyTypes();

// You can access the service through the proxy, but this sample uses the interface instead.
_service = _serviceProxy;

#region Enable Auditing for an Account
//<snippetAuditing1>
Console.WriteLine("Enabling auditing on the organization and account entities.");

// Enable auditing on the organization.
// First, get the organization's ID from the system user record.

Guid orgId = ((WhoAmIResponse)_service.Execute(new WhoAmIRequest())).OrganizationId;

// Next, retrieve the organization's record.
Organization org = _service.Retrieve(Organization.EntityLogicalName, orgId,
new ColumnSet(new string[] { "organizationid", "isauditenabled" })) as Organization;

// Finally, enable auditing on the organization.
bool organizationAuditingFlag = org.IsAuditEnabled.Value;
org.IsAuditEnabled = true;
_service.Update(org);

// Enable auditing on account entities.
bool accountAuditingFlag = EnableEntityAuditing(Account.EntityLogicalName, true);
//</snippetAuditing1>
#endregion Enable Auditing for an Account

CreateRequiredRecords();

#region Retrieve the Record Change History
Console.WriteLine("Retrieving the account change history.\n");
//<snippetAuditing5>
// Retrieve the audit history for the account and display it.
RetrieveRecordChangeHistoryRequest changeRequest = new RetrieveRecordChangeHistoryRequest();
changeRequest.Target = new EntityReference(Account.EntityLogicalName, _newAccountId);

RetrieveRecordChangeHistoryResponse changeResponse =
(RetrieveRecordChangeHistoryResponse)_service.Execute(changeRequest);

AuditDetailCollection details = changeResponse.AuditDetailCollection;
//</snippetAuditing5>

foreach (AttributeAuditDetail detail in details.AuditDetails)
{
// Display some of the detail information in each audit record.
DisplayAuditDetails(detail);
}
#endregion Retrieve the Record Change History

#region Retrieve the Attribute Change History

//**********************************************************************

*This post is locked for comments

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Not recognising WhoAmIResponse and RetrieveRecordChangeHistoryRequest in API

    That's a different namespace defined in a different dll, so there are other classes there etc..

    msdn.microsoft.com/.../microsoft.xrm.sdk.messages.aspx

  • windyMill Profile Picture
    windyMill 435 on at
    RE: Not recognising WhoAmIResponse and RetrieveRecordChangeHistoryRequest in API

    Thanks I had used using Microsoft.Xrm.Sdk.Messages in place of using Microsoft.Crm.Sdk.Messages well what is diffrence between both

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: Not recognising WhoAmIResponse and RetrieveRecordChangeHistoryRequest in API

    Hi,

      make sure you have added

    using Microsoft.Crm.Sdk.Messages;

    (and a reference to Microsoft.Crm.Sdk.Proxy.dll)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans