Forum Discussion

pgary's avatar
pgary
New Contributor
6 years ago

Comparing Two Consecutive Subobjects

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

  • aleung's avatar
    aleung
    Contributor III

    so I assume it is now working right?

    • ayush_vipul's avatar
      ayush_vipul
      New Contributor III

      Facing the same issue.

      using the following as query { entityId: $original.EntityId , "$set": { comments: "documentCount" } }

      it validates successfully but when executing getting following error.

      Failure: Failed to update documents in the MongoDB collection: uiEventsPushed, Reason: Write failed with error code 2 and error message ‘unknown top level operator: $set’, Resolution: Please address reported issue.

      Regards
      Ayush

      • tstack's avatar
        tstack
        Former Employee

        This property is only for the query portion of the operation, whereas $set is something that would be used in the update part of the operation. In other words, the property is used to find the docs in the collection to be updated, not how to update them. The snap will construct the update as a $set with the contents of the incoming document. So, you’d want the document coming into the snap to have a “comments” field with the new value.