|
![]() |
#1 |
Участник
|
Цитата:
Код: public void Execute(IServiceProvider serviceProvider) { int Count = 0; Entity entity = null; // Получаем контекст плагина IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { // Получаем объект entity = (Entity)context.InputParameters["Target"]; } else { return; } if (entity.Attributes.Contains("parentcustomerid")) { // Получаем сервис через контекст плагина IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); ConditionExpression condition = new ConditionExpression(); condition.AttributeName = "parentcustomerid"; condition.Operator = ConditionOperator.Equal; condition.Values.Add(entity.GetAttributeValue<EntityReference>("parentcustomerid").Id.ToString()); FilterExpression filter = new FilterExpression(); filter.Conditions.Add(condition); QueryExpression query = new QueryExpression("contact"); query.ColumnSet.AddColumns(new string[] { "fullname" }); query.Criteria.AddFilter(filter); EntityCollection result = service.RetrieveMultiple(query); foreach (var a in result.Entities) { Count++; } Entity account = new Entity("account"); ColumnSet attributes = new ColumnSet(new string[] { "new_contactquantity" }); account = service.Retrieve(account.LogicalName, entity.GetAttributeValue<EntityReference>("parentcustomerid").Id, attributes); //Обновляем значение поля "Количество клиентов" account["new_contactquantity"] = Count; // Обновляем запись service.Update(account); } Последний раз редактировалось Taker1796; 24.07.2012 в 12:28. |
|
![]() |
#2 |
Чайный пьяница
|
Получите поля удаяемой записи из Image.
__________________
Эмо разработчик, сначала пишу код, потом плачу над его несовершенством. Подписывайтесь на мой блог, twitter и YouTube канал. Пользуйтесь моим Ultimate Workflow Toolkit |
|
|
За это сообщение автора поблагодарили: Taker1796 (1). |
![]() |
#3 |
Участник
|
Код: if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { // Получаем объект entity = (Entity)context.InputParameters["Target"]; } else { entity = (Entity)context.PreEntityImages["PreImage"]; } |
|
![]() |
#4 |
Чайный пьяница
|
Цитата:
Сообщение от Taker1796
![]() Код: if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { // Получаем объект entity = (Entity)context.InputParameters["Target"]; } else { entity = (Entity)context.PreEntityImages["PreImage"]; }
__________________
Эмо разработчик, сначала пишу код, потом плачу над его несовершенством. Подписывайтесь на мой блог, twitter и YouTube канал. Пользуйтесь моим Ultimate Workflow Toolkit |
|
![]() |
#5 |
Участник
|
|
|
![]() |
#6 |
Чайный пьяница
|
Скриншот покажите, пожалуйста.
__________________
Эмо разработчик, сначала пишу код, потом плачу над его несовершенством. Подписывайтесь на мой блог, twitter и YouTube канал. Пользуйтесь моим Ultimate Workflow Toolkit |
|
|
|