Set Organizer for appointment or working with ActivityParty in CRM 2011


Hi,
Just posting a sample code for creating appointment record in CRM 2011.

Uri organizationUri = new Uri(<a href="http://CRM2011/orgName/XRMServices/2011/Organization.svc">http://CRM2011/orgName/XRMServices/2011/Organization.svc</a>);
Uri homeRealmUri = null;
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = new System.Net.NetworkCredential("administrator", "password", "contoso");

OrganizationServiceProxy orgProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null);
// Get the IOrganizationService
IOrganizationService orgService = (IOrganizationService)orgProxy;

// create entity record
Entity appointment = new Entity();
appointment.LogicalName = "appointment";
appointment.Attributes["subject"] = "App at " + DateTime.Now.ToString();
appointment.Attributes["scheduledstart"] = new DateTime();
appointment.Attributes["scheduledstart"] = DateTime.Now.AddDays(1);
appointment.Attributes["scheduledend"] = new DateTime();
appointment.Attributes["scheduledend"] = DateTime.Now.AddDays(1).AddHours(2);

// create activity party record
Entity activityParty = new Entity();
activityParty.LogicalName = "activityparty";
activityParty.Attributes["partyid"]=new EntityReference("systemuser",new Guid("userGuid"));
EntityCollection colAP = new EntityCollection();
colAP.Entities.Add(activityParty);

appointment.Attributes["organizer"] = new EntityCollection();
appointment.Attributes["organizer"] = colAP;

// If we use the bookrequest class it will fail
// and gives ResourceBusy error in case of scheduling conflict
// so simply create the appointment without using book request
// to make it appear in the calendar

//   BookRequest bookRequest = new BookRequest();
//   bookRequest.Target = appointment;

try
{
//  BookResponse booked = (BookResponse)orgService.Execute(bookRequest);
string appGuid = orgService.Create(appointment).ToString();
}
catch (Exception ex)
{
string exMessage = ex.Message;
}

Hope it helps !


Discover more from Nishant Rana's Weblog

Subscribe to get the latest posts sent to your email.

Unknown's avatar

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

4 thoughts on “Set Organizer for appointment or working with ActivityParty in CRM 2011”

  1. I got this below error

    System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: appointment With Id = ecf5bd3b-4fcf-4c1b-846a-8e7da4b90f08 Does Not Exist (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault).

    Like

  2. Hi,
    I am getting Error as:
    An exception of type ‘System.FormatException’ occurred in mscorlib.dll but was not handled in user code
    Additional information: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).

    This error comes on “activityParty.Attributes[“partyid”]=new EntityReference(“systemuser”,new Guid(“userGuid”));”
    Please help!!

    Like

  3. HI,
    Thanks , it worked by replacing that line with
    WhoAmIRequest userRequest = new WhoAmIRequest();
    WhoAmIResponse userResponse = (WhoAmIResponse)serviceProxy.Execute(userRequest);
    activityParty.Attributes[“partyid”] = new EntityReference(“systemuser”, userResponse.UserId);

    Like

Leave a reply to Durga Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Nishant Rana's Weblog

Subscribe now to keep reading and get access to the full archive.

Continue reading

Power Platform Puzzles

D365 CRM, Power Platform Tips &Tricks

Power Spark

Power Spark By Shrangarika

Van Carl Nguyen

Exploration of Power Platform

My Trial

It is my experience timeline.

Power⚡Thomas

Sharing my knowledge and experience about the Microsoft Power Platform.

Arpit Power Guide

a guide to powering up community

Welcome to the Blog of Paul Andrew

Sponsored by Cloud Formations Ltd

Deriving Dynamics 365

Deriving Solutions and features on Power Platform/Dynamics 365

The CRM Ninja

Thoughts & musings from a Microsoft Business Applications Ninja!

D CRM Explorer

Learn about Microsoft Dynamics CRM Power Platform customization and implementation and other cool stuffs

Stroke // Jonas Rapp

I know pre-stroke. I will improve who I was.

Power Melange

Power Melange By Shalinee

Clavin's Blog - PPUG.ORG

AI - Power Automate - Power Apps - SharePoint Online - Azure - Nintex - K2 - Artificial Intelligence

Sat Sangha Salon

An Inquiry in Being

The Indoencers

The Influencers & Influences of Indian Music

Monika Halan's blog

Hand's-free money management

D365 Demystified

A closer look at Microsoft Dynamics 365.

Microsoft Mate (msftmate) - Andrew Rogers

Experienced consultant primarily focused on Microsoft Dynamics 365 and the Power Platform

Manmit Rahevar's Blog

One Stop Destination for Microsoft Technology Solutions

MG

Naturally Curious

Brian Illand

Power Platform and Dynamics 365

Steve Mordue

The Professional Paraphraser

Subwoofer 101

Bass defines your home theater

SQLTwins by Nakul Vachhrajani

SQL Server tips and experiences dedicated to my twin daughters.

Everything D365

Discovering Azure DevOps and D365 Business Applications

Tech Wizard

Lets do IT Spells

XRM Tricks (Power Platform & Dynamics CRM )

Power Platform & Dynamics CRM

CRM TIPS BY PRM

Mail to crmtipsbyprm@gmail.com for queries and suggestions

nijos.dev

Giving back to the community what I have learned

Power Platform Learning

Your Go-To Resource for Power Apps, Power Automate & More

xrm CRM Dynamics

Dynamics CRM Technical & Functional Info

Dynamics 365 Blogs - Explained in unique way

Sometimes you need to look at things from different perspective.