Masterpage Control Script

Have a single Print Section in Designer

The section uses 4 masterpages:
image

In some cases depending on a value in record, I need to switch out the last and single masterpage to a new master pages…
I have tried a control script for it, but can’t get it to work - what am I doing wrong - there is’nt much help in the documentation?

// Page_Control Script
let section = merge.template.contexts.PRINT.sections[‘Purchase_Order’];
section = true;
// Check if 2 masterpages have to be switched out.
if (record.fields[“Note_Select”] == “Yes”){
section.sheetConfig.positions.single.masterFront = “Master Page - Single Page - Note”;
section.sheetConfig.positions.last.masterFront = “Master Page - First Page of N - Note”;
}

Just trying to understand. From your code, when record.fields[“Note_Select”] == “Yes”, you set the single and last sheet to be changed?

Single page don’t have a last one. So if single is triggerred, you won’t have a last one printed.
Only First one have a last one.

Just to clarify it…

record.fields[“Note_Select”] == “Yes I need to switch out two of the master pages.

if record.fields[“Note_Select”] == “No"
The print section uses (Depending on the number of pages)
Master Page - Single Page
Master Page - First Page of N
Master Page - Middel Page of N
Master Page - Last Page of N

if record.fields[“Note_Select”] == “Yes"
The print section uses (Depending on the number of pages)
Master Page - Single Page - Note
Master Page - First Page of N
Master Page - Middel Page of N
Master Page - Last Page of N - Note

The two master pages are replaced, cause there need to be a long text node in the bottom of the master page, and then the bottom margin, needs to be moved up on those two pages.

If it is not posible to control it with a script, is it then posible just to change the bottom margin on the two master pages - depending in the record.

Found a solution for this, endend up with this page control script:

// Page_Control Script
var section = merge.template.contexts.PRINT.sections[‘Purchase_Order’];

// Check if 2 masterpages have to be switched out.
if (record.fields[“Note_Select”] == “Yes”){
section.sheetConfig.positions.single.masterFront = “Master Page - Single Page - Note”;
section.sheetConfig.positions.last.masterFront = “Master Page - Last Page of N - Note”;
}