private void UploadAttachment(Guid recordId) { var request = new DocumentRelayRequest(); // Email attachment has been created. Query CRM to get the email attachment data var attachmentData = ReturnAttachmentData(recordId); if (attachmentData == null) { throw new InvalidPluginExecutionException("No attachment data record returned from query"); } var regardingObjectId = GetRegardingObjectId(attachmentData); if (regardingObjectId != null && (regardingObjectId.LogicalName == Application.EntityLogicalName || regardingObjectId.LogicalName == Case.EntityLogicalName)) { var direction = (bool)(attachmentData.GetAttributeValue <AliasedValue>($"email.{Email.Fields.DirectionCode}")).Value; var statusCode = (OptionSetValue)(attachmentData.GetAttributeValue <AliasedValue>($"email.{Email.Fields.StatusCode}")).Value; if (direction && statusCode.Value != 3) { //Outgoing email, do not send the attachment on create TracingService.Trace("Aborted creating attachment for outgoing email attachment that is not sent"); return; } AddInsertFileParametersToRequest(request, attachmentData); // Check there is a file to upload if (request.HasBody()) { var resultBody = SendRequest(Config[SharePointSecureConfigurationKeys.DocumentRelayLogicAppUrl], JsonConvert.SerializeObject(request)); if (resultBody != null) { TracingService.Trace("Returned from LogicApp OK"); // Get the response object DocumentRelayResponse response = JsonConvert.DeserializeObject <DocumentRelayResponse>(resultBody); TracingService.Trace($"Returned from LogicApp OK, doc url is: {response.link}"); // Create document record CreateApplicationDocument(attachmentData, request.FileDescription, request.FileName, response.link); // Delete Attachment Service.Delete(attachmentData.LogicalName, attachmentData.Id); } } else { TracingService.Trace("No file body found for Attachment. Logic app not called."); } } else { TracingService.Trace("Only attachments for emails regarding Applications, RFIs or Schedule 5s are currently sent to SharePoint"); } }
private void UploadAnnotation(Guid recordId) { var request = new DocumentRelayRequest(); // Creation of of an Annotation record on a Application or Case. var annotationData = ReturnAnnotationData(recordId); if (annotationData == null) { throw new InvalidPluginExecutionException("No annotation data record returned from query"); } // Check that Note is regarding an application or a case if (IsRegardingValidForNote(annotationData)) { AddInsertFileParametersToRequest(request, annotationData); // Check there is a file to upload if (request.HasBody()) { var resultBody = SendRequest(Config[$"{SharePointSecureConfigurationKeys.DocumentRelayLogicAppUrl}"], JsonConvert.SerializeObject(request)); if (resultBody == null) { TracingService.Trace("Returned from LogicApp, no resultBody"); return; } // Get the response object DocumentRelayResponse response = JsonConvert.DeserializeObject <DocumentRelayResponse>(resultBody); TracingService.Trace($"Returned from LogicApp OK, doc url is: {response.link}"); // Create document record CreateApplicationDocument(annotationData, request.FileDescription, request.FileName, response.link); // Blank Note Document annotationData[Annotation.Fields.NoteText] = "File has been uploaded to SharePoint."; annotationData[Annotation.Fields.DocumentBody] = string.Empty; Service.Update(annotationData); } else { TracingService.Trace("No file body found for Note. Logic app not called."); } } }