Logo Questions Linux Laravel Mysql Ubuntu Git Menu

CRM 2011 Workflows: Finding the previous values

I currently have a workflow which is triggered when a certain decimal field is changed.

Is it possible to get the difference between the old and new values via a workflow?

like image 576
user732447 Avatar asked Jun 02 '11 07:06


1 Answers

Finally had the time to test this, and it is perfectly possible to retrieve the pre values in a workflow using a workflow assembly.

Here's what I did:

I created a workflow on Contact, with a trigger on LastName. The workflow contains a reference to the field lastname, and a custom workflow assembly. I opened a contact and changed it's lastname from 'Foo' to 'Bar'

Code of the custom workflow assembly:

protected override void Execute(CodeActivityContext context)
            IWorkflowContext workflow = context.GetExtension<IWorkflowContext>();
            Entity preImage = workflow.PreEntityImages.Values.FirstOrDefault();

        string content = RetrievePreImageLastname(preImage);

        using (StreamWriter writer = new StreamWriter(@"C:\temp\log.txt", true))
            writer.WriteLine("writing workflow assembly");

    public string RetrievePreImageLastname(Entity value)
        if (value == null)
            return "PreImage is Empty";

        return string.Format("lastname pre image value: {0}", value.GetAttributeValue<string>("lastname"));

And this was the output:

writing workflow assembly

lastname pre image value: Foo

Hope this helps anyone in for future use.

like image 156
Nathan Avatar answered Sep 30 '22 11:09