web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Clearing a Cloned Product Entity Image using a Pre-Create Plugin

MagnetismXRM Profile Picture MagnetismXRM 6,230

When cloning a product using the Clone button, the new product that is created will also have the same entity image as the original product. What if you want to stop this from happening so that it has no entity image by default?

A good way to solve this would be a plugin, ideally on pre-create so you don’t have the extra update. However, while the approach of setting the entityimage field to null like the following clears the entity image on an update; in a pre-plugin, setting entityimage to null does not do anything.

Entity update = new Entity("product", target.Id); 
update["entityimage"] = null; 
Sdk.Update(update);

This is because the entityimage field does not contain any data yet, instead at this point there will be 3 fields set: entityimageid, entityimage_timestamp and entityimage_url. The entityimage_url is constructed using the first 2 fields and will end up looking something like this:

/Image/download.aspx?Entity=product&Attribute=entityimage&Id=a4ffbafc-852a-4fc3-a6c9-d7f20b0fe125&Timestamp=35718453886058129=39.

This means that, instead, we should clear these 3 fields in our pre plugin and that will prevent the entity image from being set on the new product.

target["entityimageid"] = null;
target["entityimage_timestamp"] = null;
target["entityimage_url"] = null;

Comments

*This post is locked for comments