![]() |
#8 |
Участник
|
Цитата:
Сообщение от maksii
![]() Я сомневаюсь, что мой код будет работать, хотя вроде должен.
Ну а так, если я правильно понял: Было: Код: if (!record.Contains("subject") || record["subject"].ToString() != uniq) { uniq = string.Format("{0}", uniq.Length > uniqLength ? (uniq.Substring(0, uniqLength - 3) + "...") : uniq); record["subject"] = uniq; crmService.Update(record); } Код: if (!record.Contains("subject") || record["subject"].ToString() != uniq) { uniq = string.Format("{0}", uniq.Length > uniqLength ? (uniq.Substring(0, uniqLength - 3) + "...") : uniq); record["subject"] = uniq; if(executionContext.MessageName == MessageName.Update) { crmService.Update(record); } } Код: Entity yourEntityName = (Entity)executionContext.InputParameters["Target"]; if(yourEntityName.Attributes.Contains("subject")) yourEntityName.Attributes["subject"] = yourEntityName.GetAttributeValue<EntityReference>("regardingobjectid").Name; if(executionContext.MessageName == MessageName.Update) { crmService.Update(yourEntityName ); } Код: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xrm.Sdk; using Bum.Survey.CRM.Plugin.BaseLib; using Microsoft.Xrm.Sdk.Query; using Microsoft.Xrm.Sdk.Messages; namespace Bum.Survey.CRM.Plugin { public class EvalObjectCreateTest : IPlugin { public void Execute(IServiceProvider serviceProvider) { var process = new EvalObjectCreateTestProcess(serviceProvider); process.LoadEntity(); if (!process.ValidateEntityName("bf_evaluatingobject")) return; if (!process.ValidateMessage(MessageName.Create, MessageName.Update)) return; process.Run(); } } class EvalObjectCreateTestProcess : bf_PluginProcess { public override void Execute() { if (TargetEntity.Contains("regardingobjectid")) { string uniq = ""; int uniqLength = 1024; Entity record = crmService.Retrieve(TargetEntity.LogicalName, TargetEntity.Id, new ColumnSet("subject", "regardingobjectid")); if (record.Contains("regardingobjectid")) { uniq = record.GetAttributeValue<EntityReference>("regardingobjectid").Name; RetrieveEntityRequest rerq = new RetrieveEntityRequest { LogicalName = record.GetAttributeValue<EntityReference>("regardingobjectid").LogicalName, RetrieveAsIfPublished = true }; RetrieveEntityResponse rers = (RetrieveEntityResponse)crmService.Execute(rerq); uniq = rers.EntityMetadata.DisplayName.UserLocalizedLabel.Label + " " + "[" + uniq + "]"; } if (!record.Contains("subject") || record["subject"].ToString() != uniq) { uniq = string.Format("{0}", uniq.Length > uniqLength ? (uniq.Substring(0, uniqLength - 3) + "...") : uniq); record["subject"] = uniq; if (executionContext.MessageName == MessageName.Update) { crmService.Update(record); } } } Entity yourEntityName = (Entity)executionContext.InputParameters["Target"]; if (yourEntityName.Attributes.Contains("subject")) yourEntityName.Attributes["subject"] = yourEntityName.GetAttributeValue<EntityReference>("regardingobjectid").Name; if (executionContext.MessageName == MessageName.Update) { crmService.Update(yourEntityName); } } public EvalObjectCreateTestProcess(IServiceProvider serviceProvider) : base(serviceProvider) { } } } |
|