И так, вот мой код, собственно сам вопрос добавляется в идентификатор и после того если изменить его на другой через lookup, то он меняется и в идентификаторе, но нужно ещё взять ответ (ранее упомянал как слово) с поля string и при изменении этого ответа на другой, в идентификаторе нужно чтобы тоже менялся.
Схема идентификатора: Идентификатор = Ответ (Вопрос)
Код:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using Bitforit.Survey.CRM.Plugin.BaseLib;
using Microsoft.Xrm.Sdk.Query;
namespace CRM.Plugin
{
public class AnswerBIU : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
var process = new SurveyAnswerBIUProcess(serviceProvider);
process.LoadEntity();
if (!process.ValidateEntityName("answertest")) return;
if (!process.ValidateMessage(MessageName.Create, MessageName.Update)) return;
process.Run();
}
}
class AnswerBIUProcess : cf_PluginProcess
{
public override void Execute()
{
Entity self = new Entity();
foreach (var key in TargetEntity.Attributes)
self[key.Key] = TargetEntity[key.Key];
if (executionContext.MessageName != MessageName.Create)
{
Entity record = crmService.Retrieve(TargetKey.LogicalName, TargetKey.Id, new ColumnSet("textvalue", "answer_question"));
foreach (string field in record.Attributes.Select(m => m.Key))
{
if (!self.Contains(field))
self[field] = record[field];
}
}
if (TargetEntity.Contains("answer_question") || TargetEntity.Contains("textvalue"))
{
string uniq = "";
int uniqLength = 1024;
if (self.GetAttributeValue<string>("textvalue") != null)
{
Entity answer = crmService.Retrieve(self.GetAttributeValue<EntityReference>("textvalue").Name, self.GetAttributeValue<EntityReference>("textvalue").Id, new ColumnSet("textvalue"));
if (answer.Contains("textvalue"))
{
uniq += answer.GetAttributeValue<string>("textvalue") + " ";
}
}
if (self.GetAttributeValue<EntityReference>("answer_question") != null)
{
Entity qquestion = crmService.Retrieve(self.GetAttributeValue<EntityReference>("answer_question").LogicalName, self.GetAttributeValue<EntityReference>("answer_question").Id, new ColumnSet("question_identifikator"));
if (qquestion.Contains("question_identifikator"))
{
uniq += qquestion.GetAttributeValue<string>("question_identifikator") + " ";
}
}
uniq = string.Format("{0}", uniq.Length > uniqLength ? (uniq.Substring(0, uniqLength - 3) + "...") : uniq);
TargetEntity["identifikator"] = uniq;
}
}
public AnswerBIUProcess(IServiceProvider serviceProvider)
: base(serviceProvider)
{
}
}
}