Situation:
I'm trying to map a txt file to a database. I have made my source, target, schemas and flow.
In both schemas I have a date field.
Now, before making updates, I need to check for each row if the date field in the DB is older or newer than the one in the source. If the source date is newer than the DB one, that row should be updated, else that row remains the same in the DB.
How can I make that comparison in the Data Mapper?
Solution:
This example will create target records for each source record where the incoming EmpDOB date is more recent (greater) than the database’s EmpDOB date.
Create a ForEach on the Root node of your target DB schema with the source schema’s Record node.
- Click on the Root target node
- Click on the Properties tab (Vertical “Node” tab should already be selected to make Properties tab visible)
- Click mouse cursor in ForEach text area (at this point, ForEach text area should be blank)
- Double-click on the source schema’s Record node (this should populate XPath of source Record node as seen below)
- Click on Save Properties button
Create a Local Variable on the Root node of your target DB schema that does a DBQuery function (DB --> DBQuery) to capture the date in your database for each source record
- Click on Root target node
- Click on Local Variables tab
- Type in Local Variable Name
- Put mouse cursor in Local Variable Value text area (at this point, Local Variable Value text area should be blank)
- Click on DB --> DBQuery
- Fill in DBQuery function
- Example: DBQuery {'SELECT EmpDOB FROM employee_benefits WHERE EmpSSN = $Input_TSC_EmployeeBenefits/Root/Record/EmpSSN' ,$varDBinfo ,false }
- For help on DBQuery function, please refer to Help > Mapping Functions Help in Data Mapper
- Save Local Variable
Create a local variable that uses the date-difference function
- You should already be in Root’s Local Variables tab
- Click on “Paper” icon to Add/Clear Local variable name and value text fields
- Type in a new Local Variable Name
- Put mouse cursor in Local Variable Value text area
- Click on Date --> date-difference
- Fill in date-difference function
- Example: date-difference($Input_TSC_EmployeeBenefits/Root/Record/EmpDOB,'M/dd/yyyy',$varDBQuery,'M/dd/yyyy')
- For any help on date-difference function, please refer to Help --> Mapping Functions Help in Data Mapper
- Save Local Variable
The date-difference function will return a result based on:
If First Date >= Second Date, then the result is > = 0 else < 0.
For the Record node of your target DB schema, create a mapping rule utilizing the IFF condition
- Click on the Record target node
- Click on Textual Rules tab (Vertical “Node” tab should already be selected to make Textual Rules tab visible)
- Click on Conditional --> IF CONDITIONS --> For Filtering Records
- Fill in IFF condition
- Example: IFF CONDITION{$varDateComp > 0} VALUE=[true ]
- You can double-click on date-difference variable in Parameters window that should be visible under Local Variables --> AncestorVariables to populate in rule or just type in variable name preceded by $
- Click on green check mark icon to Apply Mapping
Comments
0 comments
Article is closed for comments.