Question Status

Verified
Arpit Malhotra asked a question on 25 Aug 2014 9:23 PM

Unable to compare 2 entities in CRM 4.0 using pre/post images. I'm trying to create a plugin which would capture only change data in the field from preimage and postimage and store this in a file. Not sure if its best to use 'if' statement or 'bool'.

Any suggestions would be appreciated? :)

DynamicEntity PreEntity, PostEntity;

            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is DynamicEntity)
            {
               PreEntity = (DynamicEntity)context.InputParameters["Target"];
               
            }            
                           
          if (context.PostEntityImages.Contains("PostImage") && context.PostEntityImages["Postmage"] is DynamicEntity)
             {
                PostEntity = (DynamicEntity)context.PostEntityImages["PostImage"];
             }               

Reply
Verified Answer
Aileen Gusni responded on 25 Aug 2014 10:53 PM

Hi WickedVigour,

You cannot compare by entity.

You need to compare field by fiel.

For example

if(PreEntity["new_name"] == PostEntity["new_name"])

You cannot just compare the entity :)

Thanks.

Reply
Arpit Malhotra responded on 25 Aug 2014 11:02 PM

Thanks for your reply Aileen.

So if I'm comparing multiple fields in multiple entities. Should I just compare pre/post alias of those and store it in a file say CSV? Please correct me if I'm wrong.

Like:

if (PreEntity["attributeName"] == PostEntity["attributeName"])
             {
                 //Note the change in a file
             }

if (PreEntity["attributeName"] != PostEntity["attributeName"])
             {
                 //Note the existing value in the file
             }

Thanks for your help :)

Reply
Arpit Malhotra responded on 25 Aug 2014 11:15 PM

Thanks for your reply Aileen.

So if I'm comparing multiple fields in multiple entities. Should I just compare pre/post alias of those and store it in a file say CSV? Please correct me if I'm wrong.

Like:

PreEntity = (DynamicEntity)context.PreEntityImages["Target"];

PostEntity = (DynamicEntity)context.PostEntityImages["PostImage"];

if (PreEntity["attributeName"] == PostEntity["attributeName"])

            {

                //Note the change in a file

            }

if (PreEntity["attributeName"] != PostEntity["attributeName"])

            {

                //Note the existing value in the file

            }

Reply
Aileen Gusni responded on 25 Aug 2014 11:54 PM

Hi Arpit,

You can actually use TargetEntity to track the new value.

But, yes you are correct, that method you also can use.

Or if you want to dynamically, without using ["attributename"]

Then you can use metadata to retrieve all attribute instead using "attributename" (static)

Reply
Verified Answer
Aileen Gusni responded on 25 Aug 2014 10:53 PM

Hi WickedVigour,

You cannot compare by entity.

You need to compare field by fiel.

For example

if(PreEntity["new_name"] == PostEntity["new_name"])

You cannot just compare the entity :)

Thanks.

Reply