ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

Workaround for limitation on no. of merge fields in WordManagement

Open peterz84 opened this issue 7 years ago • 1 comments

As a result of the limitation of merging a maximum of 64 fields in Word (through WordManagement cu 5054), we need a workaround the let the user select the fields he needs in his Word file. As Business Central generates 48 fields by default, the user can only select 14 fields.

We are creating a table to store these fields (linked to the Interaction Template Code) and creating a check in our eventsubscribers on OnCreateHeaderAddFields and OnAddFieldsToMergeSource to make sure we need to add the field with code like:

WITH TempNameValueBuffer DO IF ActiveWordMergeFields.GET(InteractTemplCode,Name) THEN AddNewEntry(NewName,NewValue);

Now the problem is, we dont have the Interaction Template Code available in the eventsubscribers. Please make them available.

This might not be that simple, because it's not the value in the already existing parameters SegLine or InteractionLogEntry (these record variables are empty in OnCreateHeaderAddFields).

peterz84 avatar Aug 07 '19 12:08 peterz84

Hi @peterz84 ,

OnCreateHeaderAddFields() has both SegLine, InteractLogEntry parameters but none of them initialised because CreateHeader() is called out of context of a certain SegLine or an InteractLogEntry.

CreateHeader() is called from four places:

  • in CreateWordAttachment() and OpenWordAttachment() I don't see how to add this context. It does not exist.
  • in ExecuteMerge() I can imagine that the template code could be taken from InteractLogEntry related to the first TempDeliverySorter
  • In RunMergedDocument() there is SegLine that can define the template code.

I could add a TemplateCode parameter to CreateHeader and pass some value from ExecuteMerge() and RunMergedDocument(). Would it be enough? If we don't have to link the header to a SegLine or a InteractLogEntry you could still add fields required for any header. You could set fields in ActiveWordMergeFields with a reserved code "#HEADER#" that will be the key in the subscriber to OnCreateHeaderAddFields(): InteractTemplCode := '#HEADER#';

OnAddFieldsToMergeSource() takes either SegLine or InteractLogEntry that include

  • in ExecuteMerge() it is the InteractLogEntry
  • in RunMergedDocument() it is the SegLine

In both cases one of the parameters is a temporary record. Could you try if this check work for you in the subscriber to the OnAddFieldsToMergeSource()?

if not InteractLogEntry.IsTemporary then
    InteractTemplCode:= InteractLogEntry."Interaction Template Code"; 
if not SegLine.IsTemporary then
    InteractTemplCode:= SegLine."Interaction Template Code"; 

StanPesotskiy avatar Nov 06 '19 14:11 StanPesotskiy