showPrintPreview in for loop

Hi guys,

I seem to be running into some strange behaviour.

I have the following code

function printContracts()
{
for ( var i = 1 ; i <= currentcontroller.getMaxRecordIndex() ; i++ ) 
{ 
currentcontroller.recordIndex = i; 
if ( immocontract_to_contacts_owner.contac_language == "French" || !immocontract_to_contacts_owner )
{globals.template_refnr = 2
}
else
{globals.template_refnr = 1
}
var textrepl = utils.stringReplaceTags(templates_refnr.template_text,foundset)
contracttext2 = textrepl
forms.immocontract_contract.controller.showPrintPreview()
}
}

When this is run on a single record, it give me my preview just fine and when I close the preview i get returned to the previous form.

When this is run on multiple records though, servoy gets in quite an unstable state and the client needs to be shutdown in order to be resolved.

Could someone point out what I am doing wrong?

I have read some articles on the forum which seem to indicate one should not execute code after the preview.

Does the for loop count in this case as subsequent code execution?

Many thanks for your advice.

Regards,
John

Does anybody have any what is wrong here?

Problem started last week for the customer, nothing in the logs indicating a problem.

This has a huge impact on the customers working environment though.

I have never seen and used such kind of code,

why do you want to show printPreview in a loop?
you want for instance, if you have 5 records, 5 times a different printpreview screen? 5 times hit print, or cancel??

you can do this, by using controller.print() and than print to a pdf-file, and at the end, show that pdf…

I agree on the fact that the code is not perfect.

I did not write it in my defence :-)

I will make the form an accessible form by itself and will simply load it up with the correct dataset, make the required adaptations and then sent that set to the printcenter, lacking a better solution.

It is happening on multiple other locations where this logic is used though so i’m up for a long weekend :-)