Я пытаюсь сделать деятельность, которая переносит адрес от ведущего к контакту. Мы не используем по умолчанию Address1 и Address2 в нашем развертывании CRM (не мое решение), поэтому, хотя процесс Qualification копирует адрес, введенный в начало контакта, он делает это, используя поля Address1. Я использую код ниже, и все, кажется, работает (нет ошибок регистрации, нет ошибок, выполняющих рабочий процесс, который использует это действие). Есть только одна проблема ... ничего не происходит. Хотя ошибок нет, адрес не создается. Я работаю как администратор CRM, поэтому это не должно быть правкой, но даже если это не должно генерировать исключение безопасности? Любые идеи, почему это не работает?CRM create CustomerAddress Programmatically
public class MigrateLeadAddressToContactActivity : CodeActivity
{
[Input("Contact input")]
[ReferenceTarget("contact")]
public InArgument<EntityReference> InContact { get; set; }
protected override void Execute(CodeActivityContext executionContext)
{
// Get the tracing service
var tracingService = executionContext.GetExtension<ITracingService>();
if (InContact == null)
{
const string errorMessage = "Contact was not set for Address Migration Activity";
tracingService.Trace(errorMessage);
throw new InvalidOperationException(errorMessage);
}
// Get the context service.
var context = executionContext.GetExtension<IWorkflowContext>();
var serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
// Use the context service to create an instance of CrmService.
var service = serviceFactory.CreateOrganizationService(context.UserId);
//Retrieve the contact id
var contactId = this.InContact.Get(executionContext).Id;
// Get The Lead if it exists
var query = new QueryByAttribute
{
ColumnSet = new ColumnSet(
new[]
{
"address1_line1",
"address1_line2",
"address1_line3",
"address1_city",
"address1_stateorprovince",
"address1_postalcode",
"address1_country",
}
),
EntityName = "lead"
};
// The query will retrieve all leads whose associated contact has the desired ContactId
query.AddAttributeValue("customerid", contactId);
// Execute the retrieval.
var results = service.RetrieveMultiple(query);
var theLead = results.Entities.FirstOrDefault();
if (null == theLead)
{
tracingService.Trace("Activity exiting... Contact not sourced from Lead.");
return;
}
var newAddress = new Entity("customeraddress");
newAddress.Attributes["name"] = "business";
newAddress.Attributes["objecttypecode"] = "contact";
newAddress.Attributes["addresstypecode"] = 200000;
newAddress.Attributes["parentid"] = new CrmEntityReference("contact", contactId);
newAddress.Attributes["line1"] = theLead.Attributes["address1_line1"];
newAddress.Attributes["line2"] = theLead.Attributes["address1_line2"];
newAddress.Attributes["line3"] = theLead.Attributes["address1_line3"];
newAddress.Attributes["city"] = theLead.Attributes["address1_city"];
newAddress.Attributes["stateorprovince"] = theLead.Attributes["address1_stateorprovince"];
newAddress.Attributes["postalcode"] = theLead.Attributes["address1_postalcode"];
newAddress.Attributes["country"] = theLead.Attributes["address1_country"];
service.Create(newAddress);
tracingService.Trace("Address Migrated from Contact to Lead.");
}
Возможно ли зарегистрировать много информации? Выталкивайте все части кода, чтобы увидеть, что вы получаете, это может быть какая-то нечеткая ошибка где-то. –