cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Comparing Two Consecutive Subobjects

pgary
New Contributor

Iโ€™m trying to move job history records from one system into another using SnapLogic, and the actual data transformation is working great. However, a requirement has come up that I need to check that, in the case of workers who were terminated and later rehired, they canโ€™t have any activity in between the termination and rehire. Sometimes the data gets dirty though, and they had things like job changes or compensation changes while a worker was technically terminated listed in the system.

Iโ€™ve built the extraction and grouped each set of data, but I canโ€™t figure out how to compare the two consecutive elements so I can use it to route. So for instance:

{
โ€œgroupByโ€: {
โ€œEmployee IDโ€: โ€œ21194โ€
},
โ€œEmployeeโ€: [
{
โ€œEmployee IDโ€: โ€œ21194โ€,
โ€œEffective Dateโ€: โ€œ1/15/2009โ€,
โ€œActionโ€: โ€œHireโ€
},
{
โ€œEmployee IDโ€: โ€œ21194โ€,
โ€œEffective Dateโ€: โ€œ10/29/2009โ€,
โ€œActionโ€: โ€œTerminationโ€
},
{
โ€œEmployee IDโ€: โ€œ21194โ€,
โ€œEffective Dateโ€: โ€œ10/29/2010โ€,
โ€œActionโ€: โ€œRehireโ€
},
{
โ€œEmployee IDโ€: โ€œ21194โ€,
โ€œEffective Dateโ€: โ€œ09/14/1994โ€,
โ€œActionโ€: โ€œCompensation Changeโ€
},
]
}

I want to find the node where the action is โ€œTermiationโ€, then look at the next node and see if the action is โ€œRehireโ€, or if there is no other node after โ€œTerminationโ€ If so, that is a valid record. If not, that needs to go to a different queue for error reporting.

Iโ€™ve tried every way I can think of, and am still stuck. Can anyone help?

3 REPLIES 3

Michael
Employee
Employee

Hi, Iโ€™m not a person knowledgeable enough to give you a solution, but I was curious when I read this. It looks like a logic problem. If after termination and thereโ€™s a comp or job change action, wouldnโ€™t it always get routed to error handling (since the dirty data would occur before a rehire action, according to how you described it)?

pgary
New Contributor

What happens is that people are scheduled to be rehired. Their compensation is updated. Then their rehire date changes, but that compensation update isnโ€™t changed to match the rehire date. So you have some messy data laying around.

Now weโ€™re moving to a new system, and that system wonโ€™t allow the dirty data to be loaded. Thus I need to catch what is causing problems before we try and load anything.

ptaylor
Employee
Employee

Try this pipeline:

Community7373_2020_04_29 (1).slp (6.2 KB)

The crux is a Mapper with an expression like this:

match $.Employee.findIndex(e => e.Action == "Termination") {  
 i if i == -1 => "VALID",
 i if i == $.Employee.length - 1 => "VALID",
 i if $.Employee[i+1].Action == "Rehire" => "VALID",
 _ => "INVALID"
}