none
Workflow (who is suppose to be launch on Record change only) is been launch if a retrieve and update has been made.

    Pregunta

  • Hi all,

    I'm doing this:

    public class CalculDelaisDemande : IPlugin
        {
            public void Execute(IServiceProvider serviceProvider)
            {
                var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                var factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                var service = factory.CreateOrganizationService(context.UserId);
    
    if (context.Depth != 1)
                    return;
    
                try
                {
                    using (var orgContext = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service))
                    {
                        if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
                        {
                            var entityDemande = (Entity) context.InputParameters["Target"];
    
                            var demande = (from c in orgContext.CreateQuery<new_demande>()
                                               where c.new_demandeId == entityDemande.Id
                                              select c).FirstOrDefault();
    
                             orgContext.UpdateObject(demande);
                             orgContext.SaveChanges();
    
    .....

    A workflow is associate and should be launch on "record fields change".

    But it is always launch even though I do not change the value of the field.

    WHy?

    Anybody would know about this?

    I could not find anything on this after googling.

    Thank you


    Bernard Lessard

    viernes, 24 de febrero de 2012 17:04

Todas las respuestas

  • i think Organization context sends all the fields back to the server on update and not the changed ones. since you did call an update object on the record, it would have sent all values back to database and this caused the workflow to fire. HTH Sam

    Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    sábado, 25 de febrero de 2012 0:48
  • Can you allow the workflow to fire, but in the first step check a condition and stop as cancelled if the fields you are interested in have not changed?

    (this would probably require storing the old value in another field to compare against, and updating the old one to match if the new one genuinely has changed, just like old-school CRM 4.0 workarounds to provide very limited "auditing" of changes)


    Hope this helps. Adam Vero, MCT

    sábado, 25 de febrero de 2012 12:46