创建一个dynamics 365 CRM online plugin (三) - PostOperation
上两节我们创建了一个 PreOperation的plugin
今天我们创建一个PostOpeartion的plugin和之前的plugin连接起来
当创建contact之后,我们要添加一个task给新创建的contact
首先,我们创建新的class, 并且取名TaskCreate.cs
其次,我们把代码Execute代码复制到TaskCreate.cs中
然后我们可以从Settings -> Customization -> Customize the System 中查看Task的Form.
本次我们取subject, description, Priority 还有 Duration
因为due date为时间, priority为option, 所以在代码上和string有些许不同.
try { // Plug-in business logic goes here. Entity taskRecord = new Entity("task"); // Single line of text taskRecord.Attributes.Add("subject", "Follow up"); taskRecord.Attributes.Add("description", "Please follow up with contact."); // Date taskRecord.Attributes.Add("scheduledend", DateTime.Now.AddDays(2)); // Option set value as "High" taskRecord.Attributes.Add("prioritycode", new OptionSetValue(2)); // Parent record or Look up // You should link your assignment(Task) to the specific contact // contact.Id can ONLY be used in the Post-validation Operation due to pre-validation will not have the ID yet and it will cost the error. // taskRecord.Attributes.Add("regardingobjectid", new EntityReference("contact", contact.Id)); taskRecord.Attributes.Add("regardingobjectid", contact.ToEntityReference()); Guid taskGuid = service.Create(taskRecord); }
写好之后rebuild, 并且打开Register tool. 双击我们register的assembly.
load刚才build之后生成的dll, 并且点击确定.
我们重新创建一个contact, 这次就会发现我们的activities中有一个task