Dynamics 365中的批量删除作业执行频率可以高于每天一次吗?

微软动态CRM专家罗勇 ,回复317或者20190314可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me 。

我先来做一个例子,登录Dynamics 365 Customer Engagement以后导航到 【设置】> 【数据管理】> 【批量删除记录】,点击【新建】按钮新建一个,如下,

 

 

 可以看到我能选择的改批量删除任务执行的最高频率就是每天执行一次,如果我要更加频繁的执行频率呢?可以更改吗?根据官方文档 Recurrence pattern in asynchronous job execution 我来改改看。

待第一次运行完毕后,我用T-SQL看下这个作业,有两条记录,一条是父记录,也就是我定义的批量删除记录,另一个是运行一次后产生的记录,主要区别在于RecurrenceStartTime和RecurrencePattern字段有值,前面字段定义了什么时候开始,后面字段定义了执行频率。

 

如何更改呢,很简单啊,就改RecurrencePattern字段和recurrencestarttime字段的值,为了方便大家执行,我这里用JavaScript调用Web API来查询和更改。

        var clientURL = Xrm.Page.context.getClientUrl();
        var jobName = '删除一个月之前创建的已成功/失败/取消的系统作业';
        var req = new XMLHttpRequest();
        var jobId = "";
        req.open("GET", encodeURI(clientURL + "/api/data/v9.0/asyncoperations?$select=asyncoperationid&$orderby=createdon asc&$filter=name eq '" + jobName + "' and recurrencepattern ne null&$top=1"), true);
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.onreadystatechange = function () {
            if (this.readyState == 4) {
                req.onreadystatechange = null;
                if (this.status == 200) {
                    var responseJSON = JSON.parse(this.responseText);
                    if (responseJSON.value != null && responseJSON.value.length == 1) {
                        jobId = responseJSON.value[0].asyncoperationid;
                        req = new XMLHttpRequest();
                        req.open("PATCH", encodeURI(clientURL + "/api/data/v9.0/asyncoperations(" + jobId + ")"), true);
                        req.setRequestHeader("Accept", "application/json");
                        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                        req.setRequestHeader("OData-MaxVersion", "4.0");
                        req.setRequestHeader("OData-Version", "4.0");
                        req.onreadystatechange = function () {
                            if (this.readyState == 4 /* complete */) {
                                req.onreadystatechange = null;
                                if (this.status == 204) {
                                    Xrm.Utility.alertDialog("Operation done successfully!");
                                }
                                else {
                                    var error = JSON.parse(this.response).error;
                                    Xrm.Utility.alertDialog("Error." + error.message);
                                }
                            }
                        };
                        var requestMsg = {};
                        requestMsg["recurrencepattern"] = "FREQ=HOURLY;INTERVAL=12;";
                        requestMsg["recurrencestarttime"] = new Date();
                        req.send(JSON.stringify(requestMsg));
                    }
                    else {
                        Xrm.Utility.alertDialog("Cann't find the recurrent job " + jobName);
                    }
                }
                else {
                    var error = JSON.parse(this.responseText).error;
                    Xrm.Utility.alertDialog("Error." + error.message);
                }
            }
        };
        req.send();

可以执行,但是报错Bulk Delete and Duplicate Detection recurrence must be specified as daily.,报错信息如下:

{  
   "error":{  
      "code":"0x8004d2a0",
      "message":"Bulk Delete and Duplicate Detection recurrence must be specified as daily.",
      "innererror":{  
         "message":"Bulk Delete and Duplicate Detection recurrence must be specified as daily.",
         "type":"System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]",
         "stacktrace":"   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, ExecutionContext executionContext)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.Upsert(Entity entity)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.Update(Entity entity, UpdateOption updateOption)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.UpdateEdmEntity(CrmODataExecutionContext context, String edmEntityName, String entityKeyValue, EdmEntityObject entityObject)\r\n   at Microsoft.Crm.Extensibility.OData.EntityController.PatchEntityImplementation(String& entityName, String key, EdmEntityObject entityDelta)\r\n   at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func`1 func)\r\n   at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func`1 func)\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
      }
   }
}

 

当然,不能改到更密集的话,也没有必要用代码来改动,界面上可以操作。导航到【设置】> 【数据管理】> 【批量删除记录】,选择【定期的批量删除系统作业】这个视图,打开要更改的批量删除作业

 

点击【操作】 > 【修改定期项】

 

做合适的设置就可以了,当然,如果想取消这个,将其设置为 【从不】就可以了。

 

posted @ 2019-03-14 16:02  微软MVP(15-18)罗勇  阅读(482)  评论(0编辑  收藏  举报