开发者

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?


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");
            writer.Write(content);
        }
    }

    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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜