Help with set boundaries in script

Hi All,

Hope you are okay and well.

I have a query on setting boundaries via script.
I have this modified script for my sample data file. What I do is extract the two fields PersonName and PersonId clean the latter field then create a setVariable for a new name for the field lastPersonName.
The hard part is I want to make it the same as making it a trigger on change of LastPersonName, but I don’t know how to do this. Are you able to advice what I can do to achieve this?

var PersonName	= boundaries.get(region.createRegion("PersonName"));
logger.info(PersonName);

var linkedTo = boundaries.get(region.createRegion("PersonId"));
logger.info(linkedTo);

var newPersonName = `${PersonName[0]} - ${linkedTo[0]}`;

logger.info("newPersonName: " + newPersonName);

if (boundaries.getVariable("lastPersonName") !== null) {
	if (newPersonName !== boundaries.getVariable("lastPersonName")) {
		boundaries.set();
	}
}
boundaries.setVariable("lastPersonName", newPersonName);

Hello James,

Can you share your data sample? Because the issue could have something to do with the data sample. For example, I am getting 6 records as result when I use a data sample file with the following data and have the following boundaries script applied.

CSV data sample

MemNo;Linked To
01;01
02;01
03;02
04;04
05;04
06;06
07;07
08;11
09;11
10;11
11;11

Boundaries script

var curr = boundaries.get(region.createRegion("Linked To"))[0],
	prev = boundaries.getVariable("linkedTo");

if (prev !== null && curr !== prev) {
	boundaries.set();
}

boundaries.setVariable("linkedTo", curr);

Hi @Marten,

That worked, thanks a lot :blush:

1 Like