Giter Club home page Giter Club logo

Comments (3)

DawidPotgieter avatar DawidPotgieter commented on June 2, 2024

Hi there,

I'm afraid I don't have time right now to test your scenario, but perhaps you can try this that I've got somewhere on the wiki :

Open the plugin registration tool and register a new step under BinaryStorageOptions.Plugin.
Message = Retrieve
Primary Entity = template
Post Operation / Synchronous

Remember to add the secure and unsecure config xml.

You can test with just this, and you can add one more for "RetrieveMultiple" with the same settings.

Basically, this will tell CRM to use the plugin when reading templates, which is where I can see the email templates are stored at. I'm not certain whether your problem is on the read or create message, but I'm guessing it will actually be on the read.

Let me know how that goes.

Cheers.

Update.

Had a very quick look at this, and it seems the system creates new emails when you run a campaign. Since there's no plugins associated with campaigns, doesn't look like the email attachments work. I will see what I can do about this, can't give you a timeframe atm though...

from dynamics-crm-binary-storage-options.

DawidPotgieter avatar DawidPotgieter commented on June 2, 2024

Update 2.

If you look in the V5 branch here :

https://github.com/DawidPotgieter/Dynamics-CRM-Binary-Storage-Options/blob/V5/Source/BinaryStorageOptions/Plugin.Retrieve.cs

I've added a new method :

private Tuple<int, byte[]> SearchForAttachment(IOrganizationService service, Providers.IBinaryStorageProvider storageProvider, Entity entity, string documentBodyAttributeKey, string fileNameAttributeKey)
{
	//This is a little bit of a hack, but there really isn't very many good options.
	//When there's an error loading an email attachment, there's a good chance that crm is requesting a duplicate of an existing attachment, as that's how it seems to be stored.
	//So, go through the list of activitymimeattachments pointing to the same attachment id, and see if you can get the binary data using that.
	using (OrganizationServiceContext context = new OrganizationServiceContext(service))
	{
		var attachmentId = ((EntityReference)(from ama in context.CreateQuery(CrmConstants.AttachmentEntityName)
																					where ((EntityReference)ama[CrmConstants.AttachmentEntityId]).Id == entity.Id
																					select ama[CrmConstants.AttachmentId]).FirstOrDefault()).Id;
		var activitymimeattachmentIds = (from ama in context.CreateQuery(CrmConstants.AttachmentEntityName)
																			where (Guid)ama[CrmConstants.AttachmentId] == attachmentId
																			select ama[CrmConstants.AttachmentEntityId])
																			.ToList();

		foreach (Guid activitymimeattachmentId in activitymimeattachmentIds)
		{
			try
			{
				int fileSize = storageProvider.GetFileSize(activitymimeattachmentId, (string)entity.Attributes[fileNameAttributeKey]);
				byte[] data = storageProvider.Read(activitymimeattachmentId, (string)entity.Attributes[fileNameAttributeKey]);

				return new Tuple<int, byte[]>(fileSize, data);
			}
			catch { }
		}
	}
	return null;
}

And it's called in the catch block of the "HandleEntity" method above :

if (entity.LogicalName == CrmConstants.AttachmentEntityName)
{
	//Search for other attacments pointing to the same attachment id (not the activitymimeattachment).
	var otherData = SearchForAttachment(service, storageProvider, entity, documentBodyAttributeKey, fileNameAttributeKey);
	if (otherData != null && entity.Attributes.ContainsKey(fileNameAttributeKey))
	{
		if (entity.Attributes.ContainsKey(CrmConstants.FileSizeKey) &&
				(int)entity.Attributes[CrmConstants.FileSizeKey] == GenericConstants.EmptyBodyContentDataLength)
		{
			entity.Attributes[CrmConstants.FileSizeKey] = otherData.Item1;
		}

		if (entity.Attributes.ContainsKey(documentBodyAttributeKey) && 
				(string)entity.Attributes[documentBodyAttributeKey] == GenericConstants.EmptyBodyContent)
		{
			entity.Attributes[documentBodyAttributeKey] = Convert.ToBase64String(otherData.Item2);
		}
		return;
	}
}

You'll also need to add some constants in CrmConstants :

public const string AttachmentEntityId = "activitymimeattachmentid";
public const string AttachmentId = "attachmentid";

This seems to fix the reading issues I can see for campaign generated emails. It's a bit of a hack, but it seems to work.

Hope it helps.

from dynamics-crm-binary-storage-options.

DawidPotgieter avatar DawidPotgieter commented on June 2, 2024

Hi there,

Did you try the fix? Can I close the ticket perhaps?

from dynamics-crm-binary-storage-options.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.