Antwort

1

können Sie einen Plugin statt Benutzerdefinierte Workflow verwenden und es auf der „Retrieve“ Nachricht registrieren.

public void Execute(IServiceProvider serviceProvider) 
{ 
// Obtain the execution context from the service provider. 
Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext) 
    serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext)); 

if (context.Depth == 1) 
{ 
    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); 
    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); 

    // Obtain the target entity from the input parmameters. 
    EntityReference entity = (EntityReference)context.InputParameters["Target"]; 

    ColumnSet cols = new ColumnSet(
         new String[] { "lastname", "firstname", "address1_name" }); 

    var contact = service.Retrieve("contact", entity.Id, cols); 

    if (contact != null) 
    { 
     if (contact.Attributes.Contains("address1_name") == false) 
     { 
      Random rndgen = new Random(); 
      contact.Attributes.Add("address1_name", "first time value: " + rndgen.Next().ToString()); 
     } 
     else 
     { 
      contact["address1_name"] = "i already exist"; 
     } 
     service.Update(contact); 
    } 
    } 
} 

enter image description here

CRM 2011–Retrieve Plugin

2

Wenn Sie wollen eine benutzerdefinierte Workflow-Aktivität auszulösen, und müssen nicht alles Workflow ähnliche in, es zu tun, würde ich empfehlen, eine benutzerdefinierte Aktion zu schaffen . Es ist einem Workflow sehr ähnlich, aber CRM erstellt einen benutzerdefinierten Endpunkt, den Sie anrufen können. Es erübrigt die Überwachung von Workflow-IDs ...

Verwandte Themen