AnsweredAssumed Answered

Groovy Script

Question asked by rubykumari688792 on Oct 11, 2017
Latest reply on Oct 13, 2017 by rubykumari688792

Actually i'm trying to compare the files in my directory to pick the latest one (based on the date). But its not giving me one output, the output is equal to the number of inputs. Can anyone suggest where i'm wrong. here's the code.

Code:

import java.util.Properties;
import java.io.InputStream;

for ( int i = 0; i < dataContext.getDataCount(); i++ ) {
InputStream is = dataContext.getStream(i);
Properties props = dataContext.getProperties(i);
Properties props2 = dataContext.getProperties(i);
propValue = props.getProperty("document.dynamic.userdefined.filename");
prop2Value = props.getProperty("document.dynamic.userdefined.temp"); // is a temporary variable I'm using as DDP initially null/.
//example file = "RECDUALMENT20171010 213016.885"//example file
Integer ln = propValue.length();
propValue= propValue[11..ln-1] ;
if(prop2Value !=" "){
if(propValue <= prop2Value ){
props.setProperty("document.dynamic.userdefined.temp",propValue);
props.setProperty("document.dynamic.userdefined.filename",prop2Value);
//dataContext.storeStream(is, props);
}
else{
props.setProperty("document.dynamic.userdefined.temp",prop2Value);
props.setProperty("document.dynamic.userdefined.filename",propValue);
//dataContext.storeStream(is, props);
}
}
props.setProperty("document.dynamic.userdefined.temp",propValue);
dataContext.storeStream(is, props);
}

 

 

Thanks in advance!

Outcomes