web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Exception Invalid Party object type 9 upon creating email record

(0) ShareShare
ReportReport
Posted on by 2

I want to send a notification email after creating a contact in CRM. For that I have written the following code.. but it is throwing an exception of "Invalid Party object type 9".  any one can help plz

Thanks

c# code behind

================================================

//Get Contract Information
Entity Contract = Common.Common.RetrieveSingle("contract", "contractid", ConditionOperator.Equal, contractId);
if (Contract != null)
{
EntityReference ContactGuid = (EntityReference)Contract.Attributes["customerid"];
if (ContactGuid.Id != Guid.Empty)
{
Entity LoginInfo = Common.Common.RetrieveSingle("gr_contactlogin", "gr_contact", ConditionOperator.Equal, ContactGuid.Id);
if (LoginInfo != null)
{
UserName = LoginInfo.Attributes.Contains("gr_username") ? LoginInfo.Attributes["gr_username"].ToString() : "";
Password = LoginInfo.Attributes.Contains("gr_password") ? LoginInfo.Attributes["gr_password"].ToString() : "";
if (UserName != string.Empty && Password != string.Empty)
{
Entity ConsumerTeam = Common.Common.RetrieveSingle("team", "name", ConditionOperator.Equal, "Consumers", null);
Logger.Debug("Consumer Team with Id: " + ConsumerTeam.Id);
if (ConsumerTeam != null)
{

//Defining Activity Parties (starts)
Entity Fromparty = new Entity("activityparty");
Entity Toparty = new Entity("activityparty");

//set partyid
Toparty["partyid"] = new EntityReference("contact", ContactGuid.Id);
Fromparty["partyid"] = new EntityReference("team", ConsumerTeam.Id);


//create email entity
Entity Email = new Entity("email");
Email["from"] = new Entity[] { Fromparty };
Email["to"] = new Entity[] { Toparty };
Email["subject"] = "Account Login Information";
Email["description"] = PopulateBody(UserName,Password);
Email["directioncode"] = true;
Email["regardingobjectid"] = new EntityReference("contact", ContactGuid.Id);
Guid EmailID = Common.Common.Create(Email);


//Sending email
SendEmailRequest reqSendEmail = new SendEmailRequest();
reqSendEmail.EmailId = EmailID;//ID of created mail
reqSendEmail.TrackingToken = "";
reqSendEmail.IssueSend = true;
SendEmailResponse res = (SendEmailResponse)Common.Common.Execute(reqSendEmail);
}
}
}
}
}

===========================================================

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at

    Hi,

    zia ul haq

    The "Invalid Party object type 9" indicates that the 'Team' is not an Activity Party type.

    Team entity cannot be used as Activity Part and therefore can't be used as From field here:

    Fromparty["partyid"] = new EntityReference("team", ConsumerTeam.Id);

    You can only send as User or Queue.

    And Activity Party is usually only User, Account, Contact, and sometimes Lead.

    You cannot use Team as the From field Activity Party.

    Thank you.

  • Suggested answer
    zia ul haq Profile Picture
    2 on at

    Aileen Gusni : Thank you so much ... this worked for me .... thanks again

  • zia ul haq Profile Picture
    2 on at

    Hi,

    i have some another issue here.  email record created but the email is not sent to.

    i want the status of email is sent

    thanks

  • zia ul haq Profile Picture
    2 on at

    Sir that's i have used as mentioned above in code.... but i can't get the email in my inbox although entity record is created.

  • Aileen Gusni Profile Picture
    44,524 on at

    Hi Zia,

    What is the email status?

    Draft, Pending Send, or Sent?

    Have you configured the email setting.

  • zia ul haq Profile Picture
    2 on at

    the status shown first is  pending send.......  that did't work for me

  • zia ul haq Profile Picture
    2 on at

    even i set the status sent through C# code....  in this case it shows status is sent.... but that did't work too... the user could't receive email

  • Aileen Gusni Profile Picture
    44,524 on at

    Hi Zia,

    Changing status will have no impact.

    Have you configured the email correctly, such as using server side or email router?

  • zia ul haq Profile Picture
    2 on at

    no i did't try that..... how to configure it ? if you can help plz

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans