[Solved] Mailmerge with double data extrapolation

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Gix800
Posts: 8
Joined: Sun Jun 11, 2023 5:14 pm

[Solved] Mailmerge with double data extrapolation

Post by Gix800 »

Greetings to all.
My goal is to use, in addition to the name field to name the files created, a second field contained in the same query (city field), which will constitute the name of the folder where to place the files. It's possible?
In other words: is it possible to extrapolate two data from two different columns in the same query?
The code below works only for naming the files, but i can't extract the data of the city column as well.


dirResults = ConvertToURL("C:\Output\") '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< default folder

With myMailmerge
.DataSourceName = NameSource
.CommandType = 1
.Command = NameTable
.OutputType = com.sun.star.text.MailMergeType.FILE
.filenamefromcolumn=true
.filenameprefix= "Name" '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< output filename (name from column "name")
.SaveAsSingleFile = false
.DocumentURL = URLframe
.OutputURL = dirResults & .AddressFromColumn= "city" '<<<<<<<<<<(WRONG PART)<<<<<<< directory where to save a file (name from column "city")
.execute(array())
.dispose()
Last edited by MrProgrammer on Tue Dec 19, 2023 3:40 am, edited 1 time in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
OpenOffice 3.1 on Windows 10
Cazer
Posts: 53
Joined: Mon May 15, 2023 11:55 am

Re: Mailmerge with double data extrapolation

Post by Cazer »

It's possible to use multiple fields from your data source in a mail merge. However, unfortunately, the way you're trying to implement it isn't supported directly in the mail merge function.

But don't worry, there's a workaround. You might want to consider creating a separate script or function that runs before your mail merge, which creates the necessary directories based on the city column. This could be done in a loop that runs through each row in your data, creating the directories as it goes. Once these directories exist, you could then use the city field in the .OutputURL of your mail merge to save the files in the appropriate folders.

I hope this helps.
OpenOffice 4.1.14
OS
Gix800
Posts: 8
Joined: Sun Jun 11, 2023 5:14 pm

Re: Mailmerge with double data extrapolation

Post by Gix800 »

Thanks for the reply. I suspected that the mailmerge function didn't allow double field option. At this point I think I'll have to go the way you indicated. Just enough time to figure out how to set it up...
:)
OpenOffice 3.1 on Windows 10
Post Reply