Tuesday, 1 May 2012

Code to create Fax Entity record in CRM 2011


In this article , I am going to explain how to Create Fax Entity record

Namespace need to include 
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Discovery;
using Microsoft.Crm.Sdk.Messages;

Code to create Fax Entity

using (OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri,
                                                    serverConfig.HomeRealmUri,
                                                    serverConfig.Credentials,
                                                    serverConfig.DeviceCredentials))
{
    _serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

    // Get the current user.
    WhoAmIRequest userRequest = new WhoAmIRequest();
    WhoAmIResponse userResponse = (WhoAmIResponse)_serviceProxy.Execute(userRequest);
    Guid _userId = userResponse.UserId;

    // Create the activity party for sending and receiving the fax.
    ActivityParty party = new ActivityParty
    {
        PartyId = new EntityReference(SystemUser.EntityLogicalName, _userId)
    };

    // Create the fax object.
    Fax fax = new Fax
    {
        Subject = "Sample Fax",
        From = new ActivityParty[] { party },
        To = new ActivityParty[] { party }
    };
    Guid _faxId = _serviceProxy.Create(fax);

}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.