Asked by:
send email via custom workflow activity in crm 2011

Question
-
right , I am new to crm 2011. I have done migration froom crm 4 to crm 2011. now I need to update my custom workflow .
I have custom workflow which get entityid and send email with URL including that ID. because we cannot get the unique ID using workflow creation interface, I have this custom workflow activity.
I used below code in CRM 4 to send email with in custom workflow activity.
but when i copy it to new project all underline with red and says namespace cannot be found assembly reference missing , how do I approach this ? how do I get uniqueid and generate my url to send to customer? any ideas... your help would be great....
// Create an activity party for the email from Activityparty party = new Activityparty(); party.partyid = new Lookup(); party.partyid.type = EntityName.systemuser.ToString(); party.partyid.Value = new Guid("23D34E1B-2331-DF34-80C2-121212536FC9"); // Create an activity party for the email to activityparty party2 = new activityparty(); party2.partyid = new Lookup(); party2.partyid.type = EntityName.contact.ToString(); party2.partyid.Value = contactId; Email email = new Email(); // Set email properties email.to = new activityparty[] { party2 }; email.from = new activityparty[] { party }; email.subject = "email subject"; email.description = get_email_body(contactId.ToString(), fullname); CrmBoolean direction = new CrmBoolean(); direction.Value = true; //outgoing email.directioncode = direction; email.regardingobjectid = new Lookup(); email.regardingobjectid.type = EntityName.contact.ToString(); email.regardingobjectid.Value = contactId; TargetCreateEmail targetCreate = new TargetCreateEmail(); targetCreate.Email = email; CreateRequest request = new CreateRequest(); request.Target = targetCreate; CreateResponse response = (CreateResponse)service.Execute(request); emailID = response.id; SendEmailRequest req = new SendEmailRequest(); req.EmailId = emailID; req.TrackingToken = string.Empty; req.IssueSend = true; // Send the email message. SendEmailResponse res = (SendEmailResponse)service.Execute(req); annotation addnote = new annotation(); addnote.subject = "Sent email subject"; addnote.notetext = "sent email to contact person <more text >:" + res.Subject.ToString(); addnote.isdocument = new CrmBoolean(); addnote.isdocument.Value = false; Lookup lookup = new Lookup(); lookup.Value = contactId; addnote.objectid = lookup; addnote.objecttypecode = new EntityNameReference(); addnote.objecttypecode.Value = "contact"; service.Create(addnote);
Friday, October 12, 2012 2:05 PM
All replies
-
You might have a look at these to start:
Upgrading a CRM 4.0 Custom Workflow Activity to CRM 2011
Upgrade Plug-ins and Custom Workflow Activities to Microsoft Dynamics CRM 2011
Jason Lattimer
Friday, October 12, 2012 6:16 PMModerator -
Yes I have read the new articles on msdn, I have create new project and copied new sdk dll and using CodeActivity ....
My question is I cannot access entities by their name like en above code I am tring to send email using activityparty , email , annotation all underline and says namespace / assebly reference missing .
but I have seen code samples that are using entities start with uppercase leeters .... what am I missing here below is the start of my activity class file.
using System.Text; using System.Activities ; using Microsoft.Crm.Sdk.Messages; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Metadata; using Microsoft.Xrm.Sdk.Messages; using Microsoft.Xrm.Sdk.Query; using Microsoft.Xrm.Sdk.Workflow; namespace Crm2011SendmyICsignUpEmailWA { public class myICSignUpEmailActivity : CodeActivity { protected override void Execute(CodeActivityContext executionContext) { //Create the tracing service ITracingService tracingService = executionContext.GetExtension<ITracingService>(); //Create the context IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); Guid contactId = context.PrimaryEntityId; Guid emailID = new Guid();
Monday, October 15, 2012 8:44 AM -
If I am understanding correctly what you are referring to... in CRM 4.0 when you added the web reference to your project you ended up being able to reference the CRM object classes. So you could use
Account a = new Account(); a.name = "test";
When upgrading to the 2011 standards, you need to generate the strongly typed class files yourself before you can use that kind of notation in your code.
See this:
Create Early Bound Entity Classes with the Code Generation Tool (CrmSvcUtil.exe)
Jason Lattimer
- Proposed as answer by JLattimerMVP, Moderator Monday, October 15, 2012 1:14 PM
Monday, October 15, 2012 1:14 PMModerator -
any other approach for this please.. basically I need to send email to contact person, and add a note.
guidence would be great.
thanks
Tuesday, October 16, 2012 12:47 PM -
In your new project have you re-added the 4.0 web reference?
Use the Microsoft Dynamics CRM 4.0 (2007) Endpoint
Jason Lattimer
Tuesday, October 16, 2012 4:42 PMModerator -
No I haven't use crm 4 web reference. I have gone through the steps to xrmgenerate using crmsvcutil.exe it gave me few errors and i have sort them now it gives another error
Exiting program with exception: The server was unable to process the request due to an internal error. For more information about the error, either turn on Inc ludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs. Enable tracing and view the trace files for more information.
I have follow the steps in below url that does not do what it says either
any idea
Thursday, October 18, 2012 8:32 AM -
Are not sure where you are still having the problem - if you are still having an issue using the Crmsvcutil.exe utility, post the entire command you are running to generate the classes.
If you have gotten past this point, perhaps re-post your code and step through it with a debugger and indicate where the error is getting thrown.
Jason Lattimer
Friday, October 19, 2012 2:19 AMModerator