cancel
Showing results for 
Search instead for 
Did you mean: 

How to copy first row record in next row until next row have value

ladikrishna
New Contributor

HI experts,

I have one table  like below 

LOAN_NUMBALDATEADV.AMOUNToutstanding
123125001-01-190020 
   21 
   34 
   4525
345150001-01-190123 
   25 
   27 
   2827

I want only loan_num to be filled in next rows unless next rows have  loan_num. Below will be final output.

LOAN_NUMBALDATEADV.AMOUNToutstanding
123125001-01-190020 
123  21 
123  34 
123  4525
345150001-01-190123 
345  25 
345  27 
345  2827

 

1 ACCEPTED SOLUTION

koryknick
Employee
Employee

@ladikrishna - SnapLogic is a streaming platform and doesn't hold context of previous or next input documents - each snap works only on the current input document.  To perform the type of contextual processing you need here, we will employ the Script snap which allows us to write more complex Javascript (or Python/Ruby) code.

Attached is a sample pipeline that should do what you are looking for.  Please download and unzip the attachment, the import the SLP as a new pipeline.  The Script snap is what performs the data value replication across subsequent records until a new value is found.

I added only a handful of lines to accomplish the desired result:

Line 33 -  declare a new variable to hold the previous loan number value and initialize to an empty string

var prevLoanNum = "";

 Line 40 - create the outDoc variable as a copy of the input document 

var outDoc = new LinkedHashMap(inDoc);

Lines 42-46 - check if the current record doesn't have loan num and use prevLoanNum, or if it has a new value then assign it to prevLoanNum

if ( outDoc.LOAN_NUM == "" ) {
	outDoc.LOAN_NUM = prevLoanNum;
} else {
	prevLoanNum = outDoc.LOAN_NUM;
}

Line 48 - output the new outDoc value

Hope this helps!

 

View solution in original post

2 REPLIES 2

koryknick
Employee
Employee

@ladikrishna - SnapLogic is a streaming platform and doesn't hold context of previous or next input documents - each snap works only on the current input document.  To perform the type of contextual processing you need here, we will employ the Script snap which allows us to write more complex Javascript (or Python/Ruby) code.

Attached is a sample pipeline that should do what you are looking for.  Please download and unzip the attachment, the import the SLP as a new pipeline.  The Script snap is what performs the data value replication across subsequent records until a new value is found.

I added only a handful of lines to accomplish the desired result:

Line 33 -  declare a new variable to hold the previous loan number value and initialize to an empty string

var prevLoanNum = "";

 Line 40 - create the outDoc variable as a copy of the input document 

var outDoc = new LinkedHashMap(inDoc);

Lines 42-46 - check if the current record doesn't have loan num and use prevLoanNum, or if it has a new value then assign it to prevLoanNum

if ( outDoc.LOAN_NUM == "" ) {
	outDoc.LOAN_NUM = prevLoanNum;
} else {
	prevLoanNum = outDoc.LOAN_NUM;
}

Line 48 - output the new outDoc value

Hope this helps!

 

Hi @koryknick ,

Thanks for the solution, attached snap is working fine .