Показать сообщение отдельно
Старый 30.07.2012, 14:00   #8  
probka is offline
probka
Участник
Аватар для probka
 
98 / 11 (1) +
Регистрация: 20.02.2012
Адрес: Ростов-на-Дону
Написала плагин, воспользовавшись докладом http://crmmagic.blogspot.com/2010/02/techdays.html. Получилось следующее:

X++:
public void Execute(IPluginExecutionContext context)
        {
            if (context.MessageName != MessageName.Delete ||
                !(context.InputParameters.Contains("Target")) ||
                !(context.InputParameters["Target"] is DynamicEntity))
                return;

            DynamicEntity _grmember = (DynamicEntity) context.InputParameters["Target"];

            if (!_grmember.Properties.Contains("new_contractid"))
                return;

            Customer customer = (Customer)_grmember["new_contractid"];

            if (customer.type != EntityName.opportunity.ToString())
                return;

            Guid opportunityid = customer.Value;

            string[] fields = new string[] { "new_status" };

            ICrmService crmservice = context.CreateCrmService(true);

            RetrieveRequest request = new RetrieveRequest();
            request.ColumnSet = new ColumnSet(fields);
            request.ReturnDynamicEntities = true;

            TargetRetrieveDynamic target = new TargetRetrieveDynamic();
            target.EntityId = opportunityid;
            target.EntityName = EntityName.opportunity.ToString();

            request.Target = target;

            DynamicEntity _opportunity = (DynamicEntity)((RetrieveResponse)crmservice.Execute(request)).BusinessEntity;

            if ((string)_opportunity["new_status"] == "2")
                throw new InvalidPluginExecutionException("Вы не можете удалить этот объект!");

        }
Но дело в том, что я использую этот плагин перед удалением сущности, созданной пользователем. И у меня context.InputParameters["Target"] = Moniker. Подскажите, как преобразовать плагин?
__________________
Так победим!