Добрый день!
Второй день разбираюсь с 4-й, немного запутался с обновлением Задачи. Вешаю на Update (Post) Вот пример кода.
При update ошибка - "В экземпляре объекта не задана ссылка на объект", но я вроде и с вязываю с ActivityId.
Спасибо
X++:
public void Execute(IPluginExecutionContext context)
{
DynamicEntity entity = null;
DynamicEntity inpEntity = null;
// Check if the InputParameters property bag contains a target
// of the current operation and that target is of type DynamicEntity.
if (context.InputParameters.Properties.Contains(ParameterName.Target) &&
context.InputParameters.Properties[ParameterName.Target] is DynamicEntity)
{
// Obtain the target business entity from the input parmameters.
entity = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target];
// TODO Test for an entity type and message supported by your plug-in.
// if (entity.Name != EntityName.account.ToString()) { return; }
// if (context.MessageName != MessageName.Create.ToString()) { return; }
}
else
{
return;
}
try
{
Key inputEntityId = new Key();
/* if (inpEntity.Name == EntityName.task.ToString() ||
inpEntity.Name == EntityName.letter.ToString() ||
inpEntity.Name == EntityName.appointment.ToString() ||
inpEntity.Name == EntityName.email.ToString() ||
inpEntity.Name == EntityName.fax.ToString() ||
inpEntity.Name == EntityName.phonecall.ToString() ||
inpEntity.Name == EntityName.orderclose.ToString() ||
inpEntity.Name == EntityName.quoteclose.ToString() ||
inpEntity.Name == EntityName.incidentresolution.ToString())
{*/
if (inpEntity.Name == EntityName.task.ToString())
{
if (inpEntity.Properties.Contains("activityid"))
{
inputEntityId = ((Key)inpEntity["activityid"]);//.Value;//.ToString();
inpEntity = (DynamicEntity)context.InputParameters[ParameterName.Target];
DynamicEntity task = new DynamicEntity();
task.Name = EntityName.task.ToString();
task.Properties = new PropertyCollection();
task.Properties.Add(new StringProperty("subject", "test"));
task.Properties.Add(new KeyProperty("activityid", inputEntityId));
TargetUpdateDynamic targetUpdate = new TargetUpdateDynamic();
targetUpdate.Entity = task;
UpdateRequest update = new UpdateRequest();
update.Target = targetUpdate;
ICrmService service = context.CreateCrmService(true);
UpdateResponse updated = (UpdateResponse)service.Execute(update);
}
}
}
catch (System.Web.Services.Protocols.SoapException ex)
{
throw new InvalidPluginExecutionException(
String.Format("An error occurred in the {0} plug-in.",
this.GetType().ToString()),
ex);
}