protected override void ExecuteWorkflowLogic() { var sourceRecord = ConvertToEntityReference(Record.Get(Context.ExecutionContext)); var documentFilter = FilterXml.Get(Context.ExecutionContext); var documentsQuery = $@" <fetch> <entity name='annotation'> <attribute name='filename' /> <attribute name='documentbody' /> <filter type='and'> <condition attribute='isdocument' operator='eq' value='1' /> <condition attribute='objectid' operator='eq' value='{sourceRecord.Id}' />"; if (!string.IsNullOrEmpty(documentFilter)) { documentsQuery += documentFilter.Replace('"', '\''); } documentsQuery += @" </filter> </entity> </fetch>"; var notes = QueryWithPaging(new FetchExpression(documentsQuery)); notes.ForEach(note => { var activityattachment = new Entity("activitymimeattachment") { ["objectid"] = Email.Get(Context.ExecutionContext), ["objecttypecode"] = "email", ["body"] = note["documentbody"], ["filename"] = note["filename"] }; Context.UserService.Create(activityattachment); }); if (SendAfterOperation.Get(Context.ExecutionContext)) { base.ExecuteWorkflowLogic(); } }
// Module defining this command // Optional custom code for this activity /// <summary> /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run. /// </summary> /// <param name="context">The NativeActivityContext for the currently running activity.</param> /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns> /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks> protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context) { System.Management.Automation.PowerShell invoker = global::System.Management.Automation.PowerShell.Create(); System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName); // Initialize the arguments if (ListLog.Expression != null) { targetCommand.AddParameter("ListLog", ListLog.Get(context)); } if (LogName.Expression != null) { targetCommand.AddParameter("LogName", LogName.Get(context)); } if (ListProvider.Expression != null) { targetCommand.AddParameter("ListProvider", ListProvider.Get(context)); } if (ProviderName.Expression != null) { targetCommand.AddParameter("ProviderName", ProviderName.Get(context)); } if (Path.Expression != null) { targetCommand.AddParameter("Path", Path.Get(context)); } if (MaxEvents.Expression != null) { targetCommand.AddParameter("MaxEvents", MaxEvents.Get(context)); } if (Credential.Expression != null) { targetCommand.AddParameter("Credential", Credential.Get(context)); } if (FilterXPath.Expression != null) { targetCommand.AddParameter("FilterXPath", FilterXPath.Get(context)); } if (FilterXml.Expression != null) { targetCommand.AddParameter("FilterXml", FilterXml.Get(context)); } if (FilterHashtable.Expression != null) { targetCommand.AddParameter("FilterHashtable", FilterHashtable.Get(context)); } if (Force.Expression != null) { targetCommand.AddParameter("Force", Force.Get(context)); } if (Oldest.Expression != null) { targetCommand.AddParameter("Oldest", Oldest.Get(context)); } if (GetIsComputerNameSpecified(context) && (PSRemotingBehavior.Get(context) == RemotingBehavior.Custom)) { targetCommand.AddParameter("ComputerName", PSComputerName.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }