Write to a file from Designer

Hello,

i need to load the value in a file to a datamapper field for a record (loadtext is working for this).
Then I have to modify the value, and write it back for the next record.

How can I achieve this.

My script looks like:
var lansym = record.fields.Landsymbol_Versandadresse;

if (lansym.trim() == "AT")
{
	var nr = loadtext("C:/PlanetPress/Einzelhandel/ATNR/Number.txt");
	nr = nr.replace("07","XX");
	result = nr;
	/* not working
     file = openTextWriter("C:/PlanetPress/Einzelhandel/ATNR/Number.txt");
	file.write(result);
	file.close();
	*/
}
results.html(result);

Many thanks for your answers.

You’ll better do that in the Datamapper as in the template you can neither write to file nor do you have variables with global scope.

It would be nice to be able to write from the designer.

As we can output report file regarding page numbers generated based on record identifier from the pagination script. Note that I am also aware that we can query through the api as well. But if your set up contains multiple piece in a record, it would be handy to be able to report on that.

cheers

While you cannot write directly to a file from a template script, you can store state per record using the contentitem object and collate that on the Workflow side and write the results to file.

Variables do have global scope (script scope is not reset across records) but this only works reliably if you use a single merge engine. If a job gets split the engines have no knowledge of each other and there is no way to synchronize state. This is an awkward limitation unfortunately. You are probably better off using the data mapper as suggested above, or using the contentitem object.