|
09.02.2011, 14:55 | #1 |
Чайный пьяница
|
Покажите, пожалуйста, полный код плагина.
Что используете для работы с вебсервисом - ICrmService или CrmService? Если ICrmService, то необходимо ваш код переписать, чтобы он работал через CrmService.
__________________
Эмо разработчик, сначала пишу код, потом плачу над его несовершенством. Подписывайтесь на мой блог, twitter и YouTube канал. Пользуйтесь моим Ultimate Workflow Toolkit |
|
09.02.2011, 15:29 | #2 |
Участник
|
вот код:
Код: public void Execute(IPluginExecutionContext context) { DynamicEntity entity = null; if (context.InputParameters.Properties.Contains(ParameterName.Target) && context.InputParameters.Properties[ParameterName.Target] is DynamicEntity) { entity = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target]; } else { return; } try { lock (_sync) { // simple query to get incremental settings for this entity using (ICrmService service = context.CreateCrmService(true)) { IncrementalNumbering setting = IncrementalNumbering.GetSettings(service, entity.Name); // system generated, if its assigned ignore this record if (setting != null && !entity.Properties.Contains(setting.PropertyName)) { int next = setting.CurrentPosition + 1; StringProperty increment = new StringProperty(setting.PropertyName,setting.Prefix.ToString()+ next.ToString()); entity.Properties.Add(increment); // keep track of the latest id inside the custom entity setting.Increment(service, next); } } } } catch (System.Web.Services.Protocols.SoapException ex) { ........ } } |
|
09.02.2011, 15:35 | #3 |
Чайный пьяница
|
Код: ICrmService service = context.CreateCrmService(true); Код: CrmAuthenticationToken token = new CrmAuthenticationToken(); token.AuthenticationType = AuthenticationType.AD; token.OrganizationName = context.OrganizationName; CrmService service = new CrmService(); service.UseDefaultCredentials = true; service.Url = (string)(Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\MSCRM").GetValue("ServerUrl")) + "/2007/crmservice.asmx"; service.CrmAuthenticationTokenValue = token;
__________________
Эмо разработчик, сначала пишу код, потом плачу над его несовершенством. Подписывайтесь на мой блог, twitter и YouTube канал. Пользуйтесь моим Ultimate Workflow Toolkit |
|
10.02.2011, 10:00 | #4 |
Участник
|
Заменил код, ошибка исчезла, но при создании из возможной сделки при шаге зарегистрированном на child pipeline плагин счетчика все равно не срабатывает (увеличение не происходит и номер не присваивается)
|
|
10.02.2011, 12:57 | #5 |
Чайный пьяница
|
Код, покажите, пожалуйста. Только в этот раз полный (без троеточий, упущенных методов и т.п.).
__________________
Эмо разработчик, сначала пишу код, потом плачу над его несовершенством. Подписывайтесь на мой блог, twitter и YouTube канал. Пользуйтесь моим Ultimate Workflow Toolkit |
|
10.02.2011, 15:46 | #6 |
Участник
|
Код плагина:
Код: using System; using System.Collections.Generic; using Microsoft.Win32; using Microsoft.Crm.Sdk; using Microsoft.Crm.SdkTypeProxy; using Microsoft.Crm.SdkTypeProxy.Metadata; using Microsoft.Crm.Sdk.Query; namespace AKAutoNumber { public class AKAutoNumber : IPlugin { private string _secureInformation; private string _unsecureInformation; private static object _sync = new object(); public AKAutoNumber(string unsecureInfo, string secureInfo) { _secureInformation = secureInfo; _unsecureInformation = unsecureInfo; } // Related SDK topic: Writing a Plug-in public void Execute(IPluginExecutionContext context) { DynamicEntity entity = null; if (context.InputParameters.Properties.Contains(ParameterName.Target) && context.InputParameters.Properties[ParameterName.Target] is DynamicEntity) { entity = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target]; } else { return; } try { lock (_sync) { // simple query to get incremental settings for this entity CrmAuthenticationToken token = new CrmAuthenticationToken(); token.AuthenticationType = AuthenticationType.AD; token.OrganizationName = context.OrganizationName; CrmService service = new CrmService(); service.UseDefaultCredentials = true; service.Url = (string)(Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\MSCRM").GetValue("ServerUrl")) + "/2007/crmservice.asmx"; service.CrmAuthenticationTokenValue = token; IncrementalNumbering setting = IncrementalNumbering.GetSettings(service, entity.Name); if (setting != null && !entity.Properties.Contains(setting.PropertyName)) { int next = setting.CurrentPosition + 1; StringProperty increment = new StringProperty(setting.PropertyName,setting.Prefix.ToString()+ next.ToString()); entity.Properties.Add(increment); // keep track of the latest id inside the custom entity setting.Increment(service, next); } } } catch (System.Web.Services.Protocols.SoapException ex) { throw new InvalidPluginExecutionException( String.Format("An error occurred in the {0} plug-in.", this.GetType().ToString()), ex); } } } } Код: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Crm.Sdk; using Microsoft.Crm.SdkTypeProxy; using Microsoft.Crm.Sdk.Query; namespace AKAutoNumber { public class IncrementalNumbering { public const string SchemaName = "do_universalnumber"; public class Fields { public const string Id = "do_universalnumberid"; public const string EntityName = "do_name"; public const string PropertyName = "do_attribute"; public const string CurrentPosition = "do_count"; public const string Prefix = "do_prefix"; } public Guid Id { get; set; } public string EntityName { get; set; } public string PropertyName { get; set; } public string Prefix { get; set; } public int CurrentPosition { get; set; } public IncrementalNumbering() { } public IncrementalNumbering(DynamicEntity entity) { this.Id = (entity.Properties[Fields.Id] as Key).Value; this.EntityName = entity.Properties[Fields.EntityName].ToString(); this.PropertyName = entity.Properties[Fields.PropertyName].ToString(); this.Prefix = entity.Properties[Fields.Prefix].ToString(); this.CurrentPosition = (entity.Properties[Fields.CurrentPosition] as CrmNumber).Value; } public void Increment(CrmService service, int next) { this.CurrentPosition = next; // set before calling ToDynamic TargetUpdateDynamic target = new TargetUpdateDynamic(); target.Entity = this.ToDynamic(); UpdateRequest request = new UpdateRequest(); request.Target = target; service.Execute(request); } // see if there are any increment settings for this entity public static IncrementalNumbering GetSettings(CrmService service, string entityName) { IncrementalNumbering setting = null; QueryExpression query = new QueryExpression(); query.EntityName = IncrementalNumbering.SchemaName; query.ColumnSet = new AllColumns(); query.Criteria = new FilterExpression(); query.Criteria.FilterOperator = LogicalOperator.And; ConditionExpression condition1 = new ConditionExpression(); condition1.AttributeName = IncrementalNumbering.Fields.EntityName; condition1.Operator = ConditionOperator.Equal; condition1.Values = new object[] { entityName }; query.Criteria.AddCondition(condition1); RetrieveMultipleRequest request = new RetrieveMultipleRequest(); request.Query = query; request.ReturnDynamicEntities = true; RetrieveMultipleResponse response = service.Execute(request) as RetrieveMultipleResponse; BusinessEntityCollection results = response.BusinessEntityCollection; if (results.BusinessEntities.Count > 0) // no error checkig to see if there are 2 incrementors set for the same entity { setting = new IncrementalNumbering(results.BusinessEntities[0] as DynamicEntity); } return setting; } // should include rest of the fields, but leave it for now public DynamicEntity ToDynamic() { DynamicEntity entity = new DynamicEntity(IncrementalNumbering.SchemaName); PropertyCollection properties = new PropertyCollection(); properties.Add(new KeyProperty(Fields.Id, new Key(this.Id))); properties.Add(new CrmNumberProperty(Fields.CurrentPosition, new CrmNumber(this.CurrentPosition))); entity.Properties = properties; return entity; } } } |
|
11.02.2011, 03:47 | #7 |
Чайный пьяница
|
На первый взгляд код - правильный, но есть какая то ошибочка. Проверил у себя точки входа в плагин - работает и для парен и для чайлд пайплайна. Так что совет вам - отладить плагин вооружившись Visual Studio...
__________________
Эмо разработчик, сначала пишу код, потом плачу над его несовершенством. Подписывайтесь на мой блог, twitter и YouTube канал. Пользуйтесь моим Ultimate Workflow Toolkit |
|
|
За это сообщение автора поблагодарили: Буденый (1). |
|
Похожие темы | ||||
Тема | Ответов | |||
Плагин на изменение подразделения пользователя | 6 | |||
не срабатывает плагин | 5 | |||
Плагин на создании Заказа | 4 | |||
Тип сущности, использующей плагин | 2 | |||
Как зарегить плагин на смену State? | 8 |
Опции темы | Поиск в этой теме |
Опции просмотра | |
|