Postprocessor script with set not changing fields in output

Hello there

I tried to change some values in a post script but the field values are not changed in the output.

var totalRecords = data.records.length;
data.records[0].set({ Total: totalRecords});

The values are changed in the designer state but not in the final output.
The values are correctly logged, when i use the logger function to access to changed fields.

What am i doing wrong?

As mentioned in the online Help, the record.set() method operates on the current data record. That’s because you can only change the values before the DataMapper writes them to the database.

So you need to include the statement as part of your DM process itself (usually as the last step before the post-processing step).

Thank you Phil. I did read so much of the documentation :stuck_out_tongue: but this must have slipped my mind.

Why can i set it there without proper mitigation? There should be an proper warning?

Sample
i need to include fields from record 400 into record 1. I cant access other records in an action step?
How do i achive this? Do i really have to use two datamappers to do this?

No, you just perform your DM as usual, then you can use the Set Properties task to assign a value to the entire data set (which achieves the same thing).

Hello Phil

Then this is only possible in combination with workflow? If that’s the intened way to do this, no problem, I just want to do it as seemless as possible.

To elaborate a bit about what i am doing:
I get data from a customer and we print those on paper in segments of a few hundert sheets. I add an sheet with the details about every segment on top of each segment. There is details about how many sheets there are in total und details about the first and last sheet in the segment.
to add those details to the first record of an segement i used the post processor script. It was kind of silly because i tried so many thing, because there were no errors. it just didnt work :wink:

How would you setup this?

Thank you for your input, Tobi

How do you intend your solution in this thread?

Its the same approach, as mine?

Yes, but if you read the follow-up post, you’ll see I explain why my original post was incorrect. The script must be inside the data mapping process.
I have now amended the original post to explain that this technique cannot be used.

But in your case, you need the data.records.length property, which is not available inside the DM process (because not all records have been processed yet).

That’s why you need Workflow. Given the additional information you posted, I would make sure the DM task returns a JSON file, then I would use a script to modify that JSON file according to your needs, followed by a Update Data Records task to update the database.