cancel
Showing results for 
Search instead for 
Did you mean: 

How to get fields of previous record into current record in SAP CI Using Groovy Or XSLT mapping

nikhil_85
Participant
0 Kudos

Hi Community,

I'm working on scenario - To fetch records from SuccessFactors from EmpJob entity with query parameter fromDate and toDate , so im getting all job history of employee from SF.

I need few fields of employee from its immediate previous record in mapping for validation and want to sent these previous fields along with Current record in mapping as a source.

Input payload will be having multiple record for different user with there historical job data , i want unique records with current job record along with three fields from immediate previous job for each employee.

To identify current and previous record below is the condition :

The current record - Sort record based on seqNumber and startDate in descending order (maximum seq no must be picked) which will be having latest start date (Nearest to current date)

Immediate previous record - endDate field in previous record will be day before startDate of current record.

Below are the three fields required from immediate previous record.

1.company
2.employeeClass
3.label --> whose Locale is en_US

Input payload : Below is the payload for single employee with its current and past historical data, we may receive this for multiple users along with there historical data)

<EmpJob>
	<EmpJob>
		<userId>12345</userId>
		<customString130Nav>
			<PicklistOption>
				<picklistLabels>
					<PicklistLabel>
						<label>CurrentDC_Professional - Full Time Office</label>
						<locale>en_US</locale>
					</PicklistLabel>
					<PicklistLabel>
						<label>DC_Professionnel - Temps plein</label>
						<locale>fr_FR</locale>
					</PicklistLabel>
				</picklistLabels>
			</PicklistOption>
		</customString130Nav>
		<startDate>2023-10-09T00:00:00.000</startDate>
		<endDate>2023-10-31T00:00:00.000</endDate>
		<company>Current5010</company>
		<employeeClass>64981</employeeClass>
		<employmentType>90707</employmentType>
		<seqNumber>2</seqNumber>
	</EmpJob>
	<EmpJob>
		<userId>12345</userId>
		<customString130Nav>
			<PicklistOption>
				<picklistLabels>
					<PicklistLabel>
						<label>DC_Professional - Full Time Office</label>
						<locale>en_US</locale>
					</PicklistLabel>
					<PicklistLabel>
						<label>DC_Professionnel - Temps plein</label>
						<locale>fr_FR</locale>
					</PicklistLabel>
				</picklistLabels>
			</PicklistOption>
		</customString130Nav>
		<startDate>2023-10-09T00:00:00.000</startDate>
		<endDate>2023-10-09T00:00:00.000</endDate>
		<company>CO_DC_5010</company>
		<employeeClass>64981</employeeClass>
		<employmentType>90707</employmentType>
		<seqNumber>1</seqNumber>
	</EmpJob>
	<EmpJob>
		<userId>12345</userId>
		<customString130Nav>
			<PicklistOption>
				<picklistLabels>
					<PicklistLabel>
						<label>PreDC_Professional - Full Time Office</label>
						<locale>en_US</locale>
					</PicklistLabel>
					<PicklistLabel>
						<label>DC_Professionnel - Temps plein</label>
						<locale>fr_FR</locale>
					</PicklistLabel>
				</picklistLabels>
			</PicklistOption>
		</customString130Nav>
		<startDate>2023-08-04T00:00:00.000</startDate>
		<endDate>2023-10-08T00:00:00.000</endDate>
		<company>Previous_5010</company>
		<employeeClass>Pre64981</employeeClass>
		<employmentType>90707</employmentType>
		<seqNumber>1</seqNumber>
	</EmpJob>
</EmpJob>

Output should be like below : Im just thinking if we can add these three previous record fields into current record with prefix "pre" so it can be directly usable in mapping.

<EmpJob>
	<EmpJob>
		<userId>12345</userId>
		<customString130Nav>
			<PicklistOption>
				<picklistLabels>
					<PicklistLabel>
						<label>CurrentDC_Professional - Full Time Office</label>
						<locale>en_US</locale>
					</PicklistLabel>
				</picklistLabels>
			</PicklistOption>
		</customString130Nav>
		<startDate>2023-10-09T00:00:00.000</startDate>
		<endDate>2023-10-31T00:00:00.000</endDate>
		<company>Current5010</company>
		<employeeClass>64981</employeeClass>
		<employmentType>90707</employmentType>
		<seqNumber>2</seqNumber>
		<precompany>Previous_5010</precompany>
		<prelabel>PreDC_Professional - Full Time Office</prelabel>
		<preemployeeClass>Pre64981</preemployeeClass>
	</EmpJob>
</EmpJob><br>

I tried to achieve this using slandered mapping functions but not working, any help be appreciated.

Thanks in advance,

Nikhil

bdBais
Explorer

On xslt mapping you can user position() function to determinate you actual position and check on in -1 to see if your fields are changed before

/node/subnode[1] <---- postion(1)

/node/subnode[2] <---- postion(2)

if (not(../subnode[position()-1)/field1 = field1 )) then ( the fields are diffent) else (fields are the same)

of you can use groovy and work with external variable to save last node and check on field.

or, if node are "identical" you can check directly (in xslt) the node vs node without modification date, just selecting the 3 fields on request.

there are a lot of methods, or you can use sold Compount (it showed your fields with _previous on tag) or a subnode with <previous> field.

Or you can save every run and create a delta request, after mapping confront 2 results and check if your fields are present.

Accepted Solutions (1)

Accepted Solutions (1)

nikhil_85
Participant
0 Kudos

Hi , I'm able to achieve requirement using Content Enricher by passing day before date of startDate into SF query to get record matching with endDate and merging additional fields into original payload,thanks.

Answers (0)