Print Context as PDF Document

Hi,

Earlier a print context could be renamed to something I wanted when running “Create Email Content” in workflow. I just added: “merge.template.contexts.PRINT.sections[record.fields[‘{sectionname}’]].part = ‘My attached file name’;” in a script in the designer.

Since version 2021, it’s not longer possible. Instead I get the subject name of the email as the name for the attached file? why? And how can I change the name now?

Hi @kalle.bystrom,

Can you let us know please if record.fields['{sectionname}'] returns a value which corresponds to a existing Print Context Section Name?

I’m asking you this question because I would expect that the following JavaScript code should still be working in version 2021.x of PReS Connect or PlanetPress Connect:

merge.template.contexts.PRINT.sections["sectionName"].part = "attachmentName";

Source: ‘Parts: splitting and renaming email attachments - PReS Connect 2021.1 User Guide (link)’

Hi Marten,

Yes, record.fields[‘{sectionname}’] returns a value of an existing Print Context Section Name and it doesn´t work.

But, if it should work, then it must be a bug somewhere in my system. I will investigate.

Hi @kalle.bystrom,

Can you let us know please using the following JavaScript code in which version of PReS Connect or PlanetPress Connect works?

merge.template.contexts.PRINT.sections[record.fields['{sectionname}']].part = 'My attached file name';

The reason why I am asking this is because I am able to reproduce the issue by using the following JavaScript code:

merge.template.contexts.PRINT.section[record.fields["sectionName"]].part = "example";

However, I am not able to reproduce the issue by using the following JavaScript code instead (without a dynamic section name):

merge.template.contexts.PRINT.section["Section 1"].part = "example";

I’ve executed these tests by executing the Create Email Content Workflow plugin in version 2021.2.1 of PReS Workflow).

My exact code is the following:

merge.template.contexts.PRINT.sections[record.fields["formid"]].part = record.fields["commissionno"] + "_" + record.fields["versionno"];

It has been fully functional and working very well from 2017 (version 8? I guess) and then through some updates, I guess 2018, 2019 versions of PlanetPress Connect, and then it stopped working in 2021.2.1.8220 when I Updated. I am not sure that I ever had version 2020 so I don’t know about that version.

I seem to have the same issue as Kalle.

My code is:

merge.template.contexts.PRINT.sections[‘Invoice Email nl-BE’].part = ‘Factuur’;
merge.template.contexts.PRINT.sections[‘Invoice Email fr-BE’].part = ‘Facture’;
merge.template.contexts.PRINT.sections[‘Invoice Email en-BE’].part = ‘Invoice’;

I have also tried this variant suggested by the [documentation] with the same result:

merge.context.sections[‘Invoice Email nl-BE’].part = ‘Factuur’;
merge.context.sections[‘Invoice Email fr-BE’].part = ‘Facture’;
merge.context.sections[‘Invoice Email en-BE’].part = ‘Invoice’;

Previous code makes sure that only one of these three sections is enabled at any time.
So, I should get one attachment and it should be named Factuur, Facture or Invoice.
However, the attachment name I get, is _PlanetPress_ snippets_Email Templates_Invoice_Open.html.pdf which is the path and name of the snippet that gets loaded as the body of the email.

My version of the Designer is 2021.1.1.6675
Until I get this right, I’m using the “File > Send test email” functionality.
Was Kalle’s problem ever solved?

As a side node…
This line suggested in previous mentionned documentation

if (channel === Channel.EMAIL) {

gives me an error "channel" is not defined. Any ideas how to solve that?

Hi b.degryse,

I solved it by adding a javascript function in the control script:

function setPartName(sectionName, partName) {
	const section = merge.template.contexts.PRINT.sections[sectionName];
	if (section.enabled) {
		section.part = partName;
	}
}

And then I replaced all rows that looked like this:
merge.template.contexts.PRINT.sections[xxx].part = yyy;

With this instead:
setPartName(xxx, yyy);

And that solved it? Weird, but I’ll give it a try.

Yes, that solved it. It is a bug that should be solved in version 2023.1 or 2023.2.

Nope, it doesn’t solve it for me :frowning:

Hmm. Then I don’t know. Hope you get an answer from anyone else soon.

Good luck!

Hi @b.degryse,

According to the code you posted you’re trying to change the name of the Print context attachment; a PDF. But you also said:

the attachment name I get, is _PlanetPress_ snippets_Email Templates_Invoice_Open.html

This is confusing to me, because the name of a Print context attachment always ends in “.pdf”. The extension is static and cannot be changed. Are you sure you’re looking at the right attachment?

About the (channel === Channel.EMAIL) line, that should be (merge.channel === Channel.EMAIL).

@Sander
You’re right about the attachment name. Its name is indeed

_PlanetPress_ snippets_Email Templates_Invoice_Open.html.pdf

I’ve edited it in my original post too.
And thanks for the correction about the channel. It doesn’t fix the main issue, though.

@Marten
Can you let someone correct the mentionned page in the documentation?
Do you have any suggestions on how to fix the attachment name problem?