I need to compare data from the previous record to the record that I am currently on. I have the data set in the datamapper, but how can I compare it to the previous record? Is there a way to set a variable that can be used when the record is changed.
I’m pretty sure this isn’t possible directly in the datamapper. There isn’t really a notion of a ‘global’ variable there.
Instead, what you may have to do is to create a simple data mapper and when you process it in Workflow choose the “Output records in Metadata” option in the data mapper.
This will output the first level record values (no nested detail values) into the metadatafile that Workflow uses. You could then use the Metadata sequencer to loop through each record in the metadata. On each loop, you’d read the current value and compare it to a value stored in a variable. You’d do whatever logic you need in your true/false branch, and then you’d have to set that variable to store the current value again. So when it comes back around the next time, that variable will have the previous value, allowing you to compare the current value to it.
Now, if the purpose of this is to modify a field in the current record set, you can do so in the appropriate branch of your condition. You’ll do this with the Metadata Fields Management plugin and you’ll simply set your value to the appropriate field.
Once you’ve completed your metadata modifications and broken out of the metadata sequencer loop, you need to tell Connect that you’ve got new values to use. You can do this either by using the ‘Update Data Records’ plugin, or by using the ‘Update Records from Metadata’ option located in Create Print Content. Both do the same thing. They’ll take whatever is in your metadata file and push those values back into the Connect database for later use.
Sharne gave us a good workaround solution for that with the following script.
//Original counter script from https://learn.objectiflune.com/howto/scripts-manual-counter-designer/
var code, newCode, results = true, codeTotal = 0;
var startValue = 1;
var incrementValue = 1;
var stepToReset = 2;
var counter = record.index;
if(stepToReset) counter = ((record.index-1) % stepToReset) + 1;
if(incrementValue) counter = (counter * incrementValue)-incrementValue;
if(startValue) counter = startValue + counter;
//Change the 2 "ADDRESS5" fields below to a field that you want to track changes on.
if(counter == 1) code = record.fields.ADDRESS5;
if(counter == 2) newCode = record.fields.ADDRESS5;
if(code == newCode){ results = true; }else{ results = false;}
//From StackOverflow
function pad(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
See the original post: