protected override void Execute(CodeActivityContext executionContext) { //Create the context IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); //Entity bookresource = (Entity)service.Retrieve("bookableresourcebooking", context.PrimaryEntityId, new ColumnSet(true)); //string campaignName = (string)regCampaign.Attributes["name"]; //EntityReference ownerid = (EntityReference)regCampaign.Attributes["ownerid"]; Entity emailEntity = new Entity("email"); Entity fromParty = new Entity("activityparty"); fromParty.Attributes["partyid"] = Systemuser.Get <EntityReference>(executionContext); EntityCollection from = new EntityCollection(); from.Entities.Add(fromParty); Entity toParty = new Entity("activityparty"); toParty.Attributes["partyid"] = ContactRef.Get <EntityReference>(executionContext); EntityCollection to = new EntityCollection(); to.Entities.Add(toParty); EntityReference regarding = new EntityReference("bookableresourcebooking", context.PrimaryEntityId); emailEntity["to"] = to; emailEntity["from"] = from; emailEntity["subject"] = "Technical Report from your WorkOrder"; emailEntity["regardingobjectid"] = regarding; Guid EmailID = service.Create(emailEntity); //EntityReference abc = SourceCompaign.Get<EntityReference>(executionContext); AddAttachmentToEmailRecord(service, EmailID, BookResource.Get <EntityReference>(executionContext), PortalComment.Get <EntityReference>(executionContext)); }
public ActionResult AddPortalComment(string regardingEntityLogicalName, string regardingEntityId, string text, HttpPostedFileBase file = null, string attachmentSettings = null) { if (string.IsNullOrWhiteSpace(text) || string.IsNullOrWhiteSpace(StringHelper.StripHtml(text))) { return(new HttpStatusCodeResult(HttpStatusCode.ExpectationFailed, ResourceManager.GetString("Required_Field_Error").FormatWith(ResourceManager.GetString("Comment_DefaultText")))); } Guid regardingId; Guid.TryParse(regardingEntityId, out regardingId); var regarding = new EntityReference(regardingEntityLogicalName, regardingId); var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext); var serviceContext = dataAdapterDependencies.GetServiceContext(); var dataAdapter = new ActivityDataAdapter(dataAdapterDependencies); var settings = EntityNotesController.GetAnnotationSettings(serviceContext, attachmentSettings); var crmUser = dataAdapter.GetCRMUserActivityParty(regarding, "ownerid"); var portalUser = new Entity("activityparty"); portalUser["partyid"] = dataAdapterDependencies.GetPortalUser(); var portalComment = new PortalComment { Description = text, From = portalUser, To = crmUser, Regarding = regarding, AttachmentSettings = settings, StateCode = StateCode.Completed, StatusCode = StatusCode.Received, DirectionCode = PortalCommentDirectionCode.Incoming }; if (file != null && file.ContentLength > 0) { // Soon we will change the UI/controller to accept multiple attachments during the create dialog, so the data adapter takes in a list of attachments portalComment.FileAttachments = new IAnnotationFile[] { AnnotationDataAdapter.CreateFileAttachment(file, settings.StorageLocation) }; } var result = dataAdapter.CreatePortalComment(portalComment); if (!result.PermissionsExist) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, ResourceManager.GetString("Entity_Permissions_Have_Not_Been_Defined_Message"))); } if (!result.CanCreate) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, ResourceManager.GetString("No_Permissions_To_Create_Notes"))); } if (!result.CanAppendTo) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, ResourceManager.GetString("No_Permissions_To_Append_Record"))); } if (!result.CanAppend) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, ResourceManager.GetString("No_Permissions_To_Append_Notes"))); } if (FeatureCheckHelper.IsFeatureEnabled(FeatureNames.TelemetryFeatureUsage)) { PortalFeatureTrace.TraceInstance.LogFeatureUsage(FeatureTraceCategory.Comments, this.HttpContext, "create_comment_" + regardingEntityLogicalName, 1, regarding, "create"); } return(new HttpStatusCodeResult(HttpStatusCode.Created)); }