private void SpawnOrTurnOffRecurrance()
 {
     if (IsMessage(PluginMessage.Create, PluginMessage.Update) && IsStage(PluginStage.PostEvent) &&
         IsMode(PluginMode.Synchronous))
     {
         if (GetOptionSet(Fields.jmcg_workflowtask_.jmcg_workflowexecutiontype) != OptionSets.WorkflowTask.WorkflowExecutionType.MonitorOnly)
         {
             if (BooleanChangingToTrue(Fields.jmcg_workflowtask_.jmcg_on))
             {
                 if (!GetDateTimeField(Fields.jmcg_workflowtask_.jmcg_nextexecutiontime).HasValue)
                 {
                     SetField(Fields.jmcg_workflowtask_.jmcg_nextexecutiontime, DateTime.UtcNow);
                 }
                 var workflows = WorkflowSchedulerService.GetRecurringInstances(TargetId);
                 if (!workflows.Any())
                 {
                     WorkflowSchedulerService.StartNewContinuousWorkflowFor(TargetId);
                 }
             }
             if (BooleanChangingToFalse(Fields.jmcg_workflowtask_.jmcg_on))
             {
                 WorkflowSchedulerService.StopContinuousWorkflowFor(TargetId);
             }
         }
     }
 }
        public void SendViewNotificationEmailWithTable(string recipientType, Guid recipientId, IEnumerable <Entity> recordsToList, LocalisationService localisationService, IDictionary <string, string> aliasTypeMaps)
        {
            if (recordsToList.Any())
            {
                var crmUrl         = GetCrmURL();
                var isToOwner      = Target.GetOptionSetValue(Fields.jmcg_workflowtask_.jmcg_viewnotificationoption) == OptionSets.WorkflowTask.ViewNotificationOption.EmailOwningUsers;
                var fieldsForTable = GetViewLayoutcellFieldNames()
                                     .Except(new[] { XrmService.GetPrimaryKeyField(recordsToList.First().LogicalName) })
                                     .ToList();
                if (isToOwner && fieldsForTable.Contains("ownerid"))
                {
                    fieldsForTable.Remove("ownerid");
                }

                var appId = recipientType == Entities.systemuser
                    ? WorkflowSchedulerService.GetUserAppId(recipientId, Target.GetStringField(Fields.jmcg_workflowtask_.jmcg_fieldforteamappid))
                    : WorkflowSchedulerService.GetQueueAppId(recipientId, Target.GetStringField(Fields.jmcg_workflowtask_.jmcg_fieldforteamappid));
                var email = new HtmlEmailGenerator(XrmService, crmUrl, appId);
                email.AppendParagraph(string.Format("This is an automated notification {0} {1}"
                                                    , isToOwner ? "that you own" : "there are"
                                                    , View.GetStringField(Fields.savedquery_.name)));
                var notes = Target.GetStringField(Fields.jmcg_workflowtask_.jmcg_emailnotes);
                if (!string.IsNullOrWhiteSpace(notes))
                {
                    email.AppendParagraph(notes.Replace("\n", "<br />"));
                }
                email.AppendTable(recordsToList, localisationService, fields: fieldsForTable, aliasTypeMaps: aliasTypeMaps);
                var viewName = View.GetStringField(Fields.savedquery_.name);
                var subject  = viewName + " Notification";
                SendNotificationEmail(recipientType, recipientId, subject, email.GetContent());
            }
        }
        public void WorkflowTaskMonitorScheduleTest()
        {
            DeleteAll(Entities.account);

            var workflowName = "Test Account Target Schedule Failure";

            DeleteWorkflowTasks(workflowName);

            var account = CreateAccount();

            var scheduleFailWorkflow = GetWorkflow(workflowName);

            var initialThreshold = DateTime.UtcNow.AddDays(-3);

            var workflowTask = InitialiseValidWorkflowTask();

            workflowTask.SetLookupField(Fields.jmcg_workflowtask_.jmcg_targetworkflow, scheduleFailWorkflow);
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_nextexecutiontime, DateTime.UtcNow.AddDays(1));
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_name, workflowName);
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_sendnotificationfortargetfailures, true);
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_sendnotificationforschedulefailures, true);
            workflowTask.SetLookupField(Fields.jmcg_workflowtask_.jmcg_sendfailurenotificationsfrom, TestQueue);
            workflowTask.SetLookupField(Fields.jmcg_workflowtask_.jmcg_sendfailurenotificationsto, TestQueue);
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_minimumschedulefailuredatetime, initialThreshold);
            workflowTask = CreateAndRetrieve(workflowTask);

            //wait until the monitor completed its first check - will respawn another the check it
            Thread.Sleep(10000);

            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_nextexecutiontime, DateTime.UtcNow.AddDays(-2));
            workflowTask = UpdateFieldsAndRetreive(workflowTask, Fields.jmcg_workflowtask_.jmcg_nextexecutiontime);

            WaitTillTrue(() => WorkflowSchedulerService.GetRecurringInstancesFailed(workflowTask.Id).Any(), 60);

            WorkflowSchedulerService.StartNewMonitorWorkflowFor(workflowTask.Id);
            WaitTillTrue(() => GetRegardingEmails(workflowTask).Count() == 1, 60);
            WaitTillTrue(() => initialThreshold < Refresh(workflowTask).GetDateTimeField(Fields.jmcg_workflowtask_.jmcg_minimumschedulefailuredatetime), 60);

            workflowTask = Refresh(workflowTask);
            Thread.Sleep(1000);

            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_nextexecutiontime, DateTime.UtcNow.AddDays(-1));
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_minimumschedulefailuredatetime, DateTime.UtcNow.AddDays(-2));
            workflowTask = UpdateFieldsAndRetreive(workflowTask, Fields.jmcg_workflowtask_.jmcg_nextexecutiontime, Fields.jmcg_workflowtask_.jmcg_minimumschedulefailuredatetime);

            WorkflowSchedulerService.StartNewContinuousWorkflowFor(workflowTask.Id);
            WaitTillTrue(() => WorkflowSchedulerService.GetRecurringInstancesFailed(workflowTask.Id).Count() > 1, 60);

            WorkflowSchedulerService.StartNewMonitorWorkflowFor(workflowTask.Id);
            WaitTillTrue(() => GetRegardingEmails(workflowTask).Count() == 2, 60);

            WorkflowSchedulerService.StartNewMonitorWorkflowFor(workflowTask.Id);
            Thread.Sleep(60000);
            Assert.AreEqual(2, GetRegardingEmails(workflowTask).Count());

            XrmService.Delete(workflowTask);
            XrmService.Delete(account);
        }
        public void WorkflowTaskMonitorTurnOnTest()
        {
            var workflowTask = InitialiseValidWorkflowTask();

            workflowTask.SetLookupField(Fields.jmcg_workflowtask_.jmcg_targetworkflow, GetTargetAccountWorkflow());
            //queues required when sending
            workflowTask.SetLookupField(Fields.jmcg_workflowtask_.jmcg_sendfailurenotificationsfrom, null);
            workflowTask.SetLookupField(Fields.jmcg_workflowtask_.jmcg_sendfailurenotificationsto, null);
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_sendnotificationfortargetfailures, true);
            try
            {
                workflowTask = CreateAndRetrieve(workflowTask);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsFalse(ex is AssertFailedException);
            }

            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_sendnotificationfortargetfailures, false);
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_sendnotificationforschedulefailures, true);
            try
            {
                workflowTask = CreateAndRetrieve(workflowTask);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsFalse(ex is AssertFailedException);
            }

            workflowTask.SetLookupField(Fields.jmcg_workflowtask_.jmcg_sendfailurenotificationsfrom, TestQueue);
            try
            {
                workflowTask = CreateAndRetrieve(workflowTask);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsFalse(ex is AssertFailedException);
            }
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_sendnotificationfortargetfailures, true);
            workflowTask.SetLookupField(Fields.jmcg_workflowtask_.jmcg_sendfailurenotificationsto, TestQueue);
            workflowTask = CreateAndRetrieve(workflowTask);
            Assert.IsNotNull(workflowTask.GetField(Fields.jmcg_workflowtask_.jmcg_minimumtargetfailuredatetime));
            Assert.IsNotNull(workflowTask.GetField(Fields.jmcg_workflowtask_.jmcg_minimumschedulefailuredatetime));

            //okay need to set conditions for the target having not executed
            WaitTillTrue(() => WorkflowSchedulerService.GetMonitorInstances(workflowTask.Id).Any(), 60);

            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_on, false);
            workflowTask = UpdateFieldsAndRetreive(workflowTask, Fields.jmcg_workflowtask_.jmcg_on);
            Assert.IsFalse(WorkflowSchedulerService.GetMonitorInstances(workflowTask.Id).Any());

            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_on, true);
            workflowTask = UpdateFieldsAndRetreive(workflowTask, Fields.jmcg_workflowtask_.jmcg_on);
            Assert.IsTrue(WorkflowSchedulerService.GetMonitorInstances(workflowTask.Id).Any());
        }
Example #5
0
        protected override void Execute()
        {
            var behindSchedule = IsBehindSchedule();

            ActivityThisType.IsBehindSchedule.Set(ExecutionContext, behindSchedule);
            if (behindSchedule)
            {
                //if there is recurring instance, but we are behind schedule
                //then probably went into an error waiting state
                //so lets stop it
                try
                {
                    WorkflowSchedulerService.StopContinuousWorkflowFor(TargetId);
                }
                catch (Exception ex)
                {
                    Trace(string.Format("Error stopping continuous workflows: {0}", ex.XrmDisplayString()));
                }
                //and start a fresh continuous one
                try
                {
                    WorkflowSchedulerService.StartNewContinuousWorkflowFor(TargetId);
                }
                catch (Exception ex)
                {
                    Trace(string.Format("Error starting continuous workflow: {0}", ex.XrmDisplayString()));
                }
            }
            if (behindSchedule && Target.GetBoolean(Fields.jmcg_workflowtask_.jmcg_sendnotificationforschedulefailures))
            {
                var recipientQueue = Target.GetLookupGuid(Fields.jmcg_workflowtask_.jmcg_sendfailurenotificationsto);
                if (!recipientQueue.HasValue)
                {
                    throw new NullReferenceException(string.Format("Error required field {0} is empty on the target {1}", XrmService.GetFieldLabel(Fields.jmcg_workflowtask_.jmcg_sendfailurenotificationsto, TargetType), XrmService.GetEntityLabel(TargetType)));
                }

                var crmUrl = GetCrmURL();
                var email  = new HtmlEmailGenerator(XrmService, crmUrl, null);
                email.AppendParagraph(string.Format("This is an automated notification that the {0} named '{1}' fell behind schedule. The system has attempted to restart the continuous workflow but any failed instance should be reviewed"
                                                    , XrmService.GetEntityLabel(TargetType)
                                                    , Target.GetStringField(Fields.jmcg_workflowtask_.jmcg_name)));
                if (!string.IsNullOrWhiteSpace(crmUrl))
                {
                    email.AppendParagraph(email.CreateHyperlink(email.CreateUrl(Target), "Open " + XrmService.GetEntityLabel(TargetType)));
                }

                var subject = XrmService.GetEntityLabel(TargetType) + " Schedule Failure: " + Target.GetStringField(Fields.jmcg_workflowtask_.jmcg_name);
                SendNotificationEmail(Entities.queue, recipientQueue.Value, subject, email.GetContent());

                Target.SetField(Fields.jmcg_workflowtask_.jmcg_minimumschedulefailuredatetime, DateTime.UtcNow);
                XrmService.Update(Target, new[] { Fields.jmcg_workflowtask_.jmcg_minimumschedulefailuredatetime });
            }
        }
Example #6
0
 internal void SuspendDelivery()
 {
     lock (this.locker)
     {
         WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "TimerEventSubscriptionQueue: {0} Suspend", new object[] { this.instanceId });
         WorkflowSchedulerService service      = this.executor.GetService(typeof(WorkflowSchedulerService)) as WorkflowSchedulerService;
         TimerEventSubscription   subscription = this.queue.Peek();
         if (subscription != null)
         {
             service.Cancel(subscription.SubscriptionId);
         }
     }
 }
Example #7
0
 internal void ResumeDelivery()
 {
     lock (this.locker)
     {
         WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "TimerEventSubscriptionQueue: {0} Resume", new object[] { this.instanceId });
         WorkflowSchedulerService service      = this.executor.GetService(typeof(WorkflowSchedulerService)) as WorkflowSchedulerService;
         TimerEventSubscription   subscription = this.queue.Peek();
         if (subscription != null)
         {
             service.Schedule(this.executor.ProcessTimersCallback, subscription.WorkflowInstanceId, subscription.ExpiresAt, subscription.SubscriptionId);
         }
     }
 }
        public void WorkflowTaskOnOffTest()
        {
            var workflowTask = InitialiseValidWorkflowTask();

            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_on, false);
            workflowTask = CreateAndRetrieve(workflowTask);
            Assert.IsFalse(WorkflowSchedulerService.GetRecurringInstances(workflowTask.Id).Any());
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_on, true);
            workflowTask = UpdateFieldsAndRetreive(workflowTask, Fields.jmcg_workflowtask_.jmcg_on);
            Assert.IsTrue(WorkflowSchedulerService.GetRecurringInstances(workflowTask.Id).Any());
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_on, false);
            workflowTask = UpdateFieldsAndRetreive(workflowTask, Fields.jmcg_workflowtask_.jmcg_on);
            WaitTillTrue(() => !WorkflowSchedulerService.GetRecurringInstances(workflowTask.Id).Any(), 60);
        }
        public void WorkflowTaskTurnOffIfDeactivatedTest()
        {
            var workflowTask = InitialiseValidWorkflowTask();

            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_on, true);
            workflowTask = CreateAndRetrieve(workflowTask);

            Assert.IsTrue(workflowTask.GetBoolean(Fields.jmcg_workflowtask_.jmcg_on));
            Assert.IsTrue(WorkflowSchedulerService.GetRecurringInstances(workflowTask.Id).Any());

            XrmService.Deactivate(workflowTask);
            workflowTask = Refresh(workflowTask);
            Assert.IsFalse(workflowTask.GetBoolean(Fields.jmcg_workflowtask_.jmcg_on));
            Assert.IsFalse(WorkflowSchedulerService.GetRecurringInstances(workflowTask.Id).Any());
        }
 private void SpawnMonitorInstance()
 {
     if (IsMessage(PluginMessage.Create, PluginMessage.Update) && IsStage(PluginStage.PostEvent) &&
         IsMode(PluginMode.Synchronous))
     {
         if (BooleanChangingToTrue(Fields.jmcg_workflowtask_.jmcg_on))
         {
             WorkflowSchedulerService.StartNewMonitorWorkflowFor(TargetId);
         }
         if (BooleanChangingToFalse(Fields.jmcg_workflowtask_.jmcg_on))
         {
             WorkflowSchedulerService.StopMonitorWorkflowFor(TargetId);
         }
     }
 }
        void ValidateWorkflowRuntime(WorkflowRuntime workflowRuntime)
        {
            if (workflowRuntime.IsStarted)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.WorkflowRuntimeStartedBeforeHostOpen)));
            }

            WorkflowSchedulerService workflowSchedulerService = workflowRuntime.GetService <WorkflowSchedulerService>();

            if (!(workflowSchedulerService is SynchronizationContextWorkflowSchedulerService))
            {
                if (workflowSchedulerService != null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.WrongSchedulerServiceRegistered)));
                }
                workflowRuntime.AddService(new SynchronizationContextWorkflowSchedulerService());
            }
        }
        public void WorkflowTaskMonitorOnlyTest()
        {
            var workflowName = "Test Account Target Failure";
            var taskName     = "Test Monitor Only";

            DeleteWorkflowTasks(taskName);

            var workflowWillFail = GetWorkflow(workflowName);
            //create the workflow task montior only
            var workflowTask = new Entity(Entities.jmcg_workflowtask);

            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_name, taskName);
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_notesfortargetfailureemail, "These are some fake instructions\nto fix the problem");
            workflowTask.SetLookupField(Fields.jmcg_workflowtask_.jmcg_targetworkflow, workflowWillFail);
            workflowTask.SetOptionSetField(Fields.jmcg_workflowtask_.jmcg_workflowexecutiontype,
                                           OptionSets.WorkflowTask.WorkflowExecutionType.MonitorOnly);
            workflowTask.SetLookupField(Fields.jmcg_workflowtask_.jmcg_sendfailurenotificationsfrom, TestQueue);
            workflowTask.SetLookupField(Fields.jmcg_workflowtask_.jmcg_sendfailurenotificationsto, TestQueue);
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_on, true);
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_crmbaseurl, "jmcg_wstestsettings.jmcg_crminstanceurl");
            workflowTask = CreateAndRetrieve(workflowTask);

            //wait a second and verify only the montior workflow spawned
            //i.e this doesn't have a continuous workflow as it doesn't
            //run a process on a schedule it just monitors
            Thread.Sleep(5000);
            Assert.IsFalse(WorkflowSchedulerService.GetRecurringInstances(workflowTask.Id).Any());
            Assert.IsTrue(WorkflowSchedulerService.GetMonitorInstances(workflowTask.Id).Any());
            //stop the monitor we will start it again in a second
            WorkflowSchedulerService.StopMonitorWorkflowFor(workflowTask.Id);

            //run the workflow which will fail
            var account = CreateAccount();

            XrmService.StartWorkflow(workflowWillFail.Id, account.Id);
            //wait a second and spawn the monitor
            Thread.Sleep(5000);
            WorkflowSchedulerService.StartNewMonitorWorkflowFor(workflowTask.Id);
            //verify the notification email created
            WaitTillTrue(() => GetRegardingEmails(workflowTask).Any(), 60);

            DeleteMyToday();
        }
        public void WorkflowTaskMonitorTargetsTest()
        {
            var initialMinumumThreshold = DateTime.UtcNow.AddDays(-1);

            DeleteAll(Entities.account, true);
            var workflowName = "Test Account Target Failure";

            DeleteWorkflowTasks(workflowName);

            var scheduleFailWorkflow = GetWorkflow(workflowName);

            DeleteSystemJobs(scheduleFailWorkflow);

            var account = CreateAccount();

            var workflowTask = InitialiseValidWorkflowTask();

            workflowTask.SetLookupField(Fields.jmcg_workflowtask_.jmcg_targetworkflow, scheduleFailWorkflow);
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_nextexecutiontime, DateTime.UtcNow.AddDays(1));
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_name, workflowName);
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_sendnotificationfortargetfailures, true);
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_sendnotificationforschedulefailures, true);
            workflowTask.SetLookupField(Fields.jmcg_workflowtask_.jmcg_sendfailurenotificationsfrom, TestQueue);
            workflowTask.SetLookupField(Fields.jmcg_workflowtask_.jmcg_sendfailurenotificationsto, TestQueue);
            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_minimumtargetfailuredatetime, initialMinumumThreshold);
            workflowTask = CreateAndRetrieve(workflowTask);

            //wait until the monitor completed its first check - will respawn another the check it
            Thread.Sleep(10000);

            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_nextexecutiontime, DateTime.UtcNow.AddDays(-2));
            workflowTask = UpdateFieldsAndRetreive(workflowTask, Fields.jmcg_workflowtask_.jmcg_nextexecutiontime);

            WaitTillTrue(() => Refresh(workflowTask).GetDateTimeField(Fields.jmcg_workflowtask_.jmcg_nextexecutiontime) > DateTime.UtcNow.AddDays(-1), 60);

            var workflow = CreateWorkflowInstance <TargetWorkflowTaskMonitorInstance>(workflowTask);

            WaitTillTrue(() => workflow.HasNewFailure(), 60);

            WorkflowSchedulerService.StartNewMonitorWorkflowFor(workflowTask.Id);

            //okay need to set conditions for the target having not executed
            WaitTillTrue(() => GetRegardingEmails(workflowTask).Any(), 60);

            WaitTillTrue(() => Refresh(workflowTask).GetDateTimeField(Fields.jmcg_workflowtask_.jmcg_minimumtargetfailuredatetime) > initialMinumumThreshold, 60);
            workflowTask = Refresh(workflowTask);
            workflow     = CreateWorkflowInstance <TargetWorkflowTaskMonitorInstance>(workflowTask);

            Assert.IsFalse(workflow.HasNewFailure());

            Thread.Sleep(1000);

            workflowTask.SetField(Fields.jmcg_workflowtask_.jmcg_nextexecutiontime, DateTime.UtcNow.AddDays(-2));
            workflowTask = UpdateFieldsAndRetreive(workflowTask, Fields.jmcg_workflowtask_.jmcg_nextexecutiontime);
            workflow     = CreateWorkflowInstance <TargetWorkflowTaskMonitorInstance>(workflowTask);

            WaitTillTrue(() => workflow.HasNewFailure(), 60);

            XrmService.Delete(workflowTask);
            XrmService.Delete(account);
        }
 private void ValidateTarget()
 {
     if (IsMessage(PluginMessage.Create, PluginMessage.Update) && IsStage(PluginStage.PreOperationEvent))
     {
         if (FieldChanging(Fields.jmcg_workflowtask_.jmcg_targetworkflow,
                           Fields.jmcg_workflowtask_.jmcg_workflowexecutiontype
                           , Fields.jmcg_workflowtask_.jmcg_fetchquery
                           , Fields.jmcg_workflowtask_.jmcg_targetviewid))
         {
             var requiredTargetedType = Entities.jmcg_workflowtask;
             //if a fetch target validate the fetch and get its target type
             var type = GetOptionSet(Fields.jmcg_workflowtask_.jmcg_workflowexecutiontype);
             switch (type)
             {
             case OptionSets.WorkflowTask.WorkflowExecutionType.TargetPerFetchResult:
             case OptionSets.WorkflowTask.WorkflowExecutionType.TargetPerViewResult:
             {
                 var fetch = GetStringField(Fields.jmcg_workflowtask_.jmcg_fetchquery);
                 if (type == OptionSets.WorkflowTask.WorkflowExecutionType.TargetPerViewResult)
                 {
                     var savedQueryId = GetStringField(Fields.jmcg_workflowtask_.jmcg_targetviewid);
                     if (string.IsNullOrWhiteSpace(savedQueryId))
                     {
                         throw new InvalidPluginExecutionException(string.Format("{0} is required when {1} is {2}", GetFieldLabel(Fields.jmcg_workflowtask_.jmcg_targetviewid),
                                                                                 GetFieldLabel(Fields.jmcg_workflowtask_.jmcg_workflowexecutiontype), GetOptionLabel(OptionSets.WorkflowTask.WorkflowExecutionType.TargetPerViewResult, Fields.jmcg_workflowtask_.jmcg_workflowexecutiontype)));
                     }
                     var savedQuery = XrmService.Retrieve(Entities.savedquery, new Guid(savedQueryId));
                     fetch = savedQuery.GetStringField(Fields.savedquery_.fetchxml);
                 }
                 if (fetch.IsNullOrWhiteSpace())
                 {
                     throw new InvalidPluginExecutionException(string.Format("{0} is required when {1} is {2}", GetFieldLabel(Fields.jmcg_workflowtask_.jmcg_fetchquery),
                                                                             GetFieldLabel(Fields.jmcg_workflowtask_.jmcg_workflowexecutiontype), GetOptionLabel(OptionSets.WorkflowTask.WorkflowExecutionType.TargetPerFetchResult, Fields.jmcg_workflowtask_.jmcg_workflowexecutiontype)));
                 }
                 try
                 {
                     requiredTargetedType = XrmService.ConvertFetchToQueryExpression(fetch).EntityName.ToLower();
                 }
                 catch (Exception ex)
                 {
                     throw new InvalidPluginExecutionException(string.Format("There was an error validating {0} it could not be converted to a {1}", GetFieldLabel(Fields.jmcg_workflowtask_.jmcg_fetchquery), typeof(QueryExpression).Name), ex);
                 }
                 break;
             }
             }
             if (type != OptionSets.WorkflowTask.WorkflowExecutionType.ViewNotification)
             {
                 var targetWorkflowId = GetLookupGuid(Fields.jmcg_workflowtask_.jmcg_targetworkflow);
                 if (!targetWorkflowId.HasValue)
                 {
                     throw new InvalidPluginExecutionException(string.Format("{0} is required", GetFieldLabel(Fields.jmcg_workflowtask_.jmcg_targetworkflow)));
                 }
                 if (type != OptionSets.WorkflowTask.WorkflowExecutionType.MonitorOnly)
                 {
                     var workflow = WorkflowSchedulerService.GetWorkflow(targetWorkflowId.Value);
                     if (workflow.GetStringField(Fields.workflow_.primaryentity) != requiredTargetedType)
                     {
                         throw new InvalidPluginExecutionException(
                                   string.Format(
                                       "Error the {0} targets the entity type of {1} but was expected to target the type {2}"
                                       , GetFieldLabel(Fields.jmcg_workflowtask_.jmcg_targetworkflow),
                                       workflow.GetStringField(Fields.workflow_.primaryentity), requiredTargetedType));
                     }
                 }
             }
         }
     }
 }
Example #15
0
 private void DoIt()
 {
     WorkflowSchedulerService.StartNewMonitorWorkflowFor(TargetId);
 }
Example #16
0
 private void DoIt()
 {
     WorkflowSchedulerService.StartNewContinuousWorkflowFor(TargetId);
 }