|
|
|
|
#1 |
|
Участник
|
Заметил ещё такой момент, при регистрации шага с child pipeline сам счетчик увеличил свое значение, но по всем видимости не смог обновить заказ, так как он был заблокирован системой
|
|
|
|
|
#2 |
|
Чайный пьяница
|
Покажите, пожалуйста, полный код плагина.
Что используете для работы с вебсервисом - ICrmService или CrmService? Если ICrmService, то необходимо ваш код переписать, чтобы он работал через CrmService.
__________________
Эмо разработчик, сначала пишу код, потом плачу над его несовершенством. Подписывайтесь на мой блог, twitter и YouTube канал. Пользуйтесь моим Ultimate Workflow Toolkit |
|
|
|
|
#3 |
|
Участник
|
вот код:
Код: 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)
{
........
}
} |
|
|
|
|
#4 |
|
Чайный пьяница
|
Код: 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 |
|
|
|
|
#5 |
|
Участник
|
Заменил код, ошибка исчезла, но при создании из возможной сделки при шаге зарегистрированном на child pipeline плагин счетчика все равно не срабатывает (увеличение не происходит и номер не присваивается)
|
|
|
|
|
#6 |
|
Чайный пьяница
|
Код, покажите, пожалуйста. Только в этот раз полный (без троеточий, упущенных методов и т.п.).
__________________
Эмо разработчик, сначала пишу код, потом плачу над его несовершенством. Подписывайтесь на мой блог, twitter и YouTube канал. Пользуйтесь моим Ultimate Workflow Toolkit |
|
|
|
|
#7 |
|
Участник
|
Код плагина:
Код: 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;
}
}
} |
|
|
|
|
Похожие темы
|
||||
| Тема | Ответов | |||
| Плагин на изменение подразделения пользователя | 6 | |||
| не срабатывает плагин | 5 | |||
| Плагин на создании Заказа | 4 | |||
| Тип сущности, использующей плагин | 2 | |||
| Как зарегить плагин на смену State? | 8 | |||
| Опции темы | Поиск в этой теме |
| Опции просмотра | |
|