Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

how to archive a file which is 90 days older than the run date passed during job run

Hi,

I will pass run date (format: yyyymmdd) during job run and i have to archive the files from a folder which are 90 days old from the run date which i have passed.

 

The files in the folder are of the format

 

abcdefgh.Dyyyymmdd. 

How can this be achieved

Labels (2)
25 Replies
TRF
Champion II
Champion II

I suppose the date passed to job reside in a context variable named "inDate" with data type String.

First you need to compute the value for "context.inDate - 90 days".

You can to that within a tSetGlobalVar component to define a global variable named "referenceDate" like this:

0683p000009M7vj.png

Then you need to get files in the source folder using tFileList.

Connect the tFileList component to an other tSetGlobalVar using the "Iterate" row.

Into the tSetGlobalVar component you will get the date part from the filename for each file you:

0683p000009M83Q.png

Connect tFileCopy to this tSetGlobalVar using an "If" trigger with the following expression:

((String)globalMap.get("referenceDate")).compareTo((String)globalMap.get("fileDate")) <= 0

Finally, configure the tFileCopy component as need to archive the current file:

0683p000009M877.png

Current will be moved to the folder designed by "archiveFolder" context variable.

Anonymous
Not applicable
Author

0683p000009M7tT.pngjob design

Hi,

 

Should the job be designed like given above or there should be 2  different tfilelist components ?

when i ran the above job i got the following error for the tsetglobalvar_2:-

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method replaceALL(String, String) is undefined for the type String.

Not sure whether i have designed it wrong.

TRF
Champion II
Champion II

Change replaceALL by replaceAll
Anonymous
Not applicable
Author


I have changed it like that and ran the job but now it throws the below error-
tSetGlobalVar_2 null
[statistics] disconnected
Exception in component tSetGlobalVar_2
java.lang.NullPointerException

TRF
Champion II
Champion II

Share the component settings
TRF
Champion II
Champion II

Here is what your job should look like:

0683p000009M88t.png

tSetGlobalVar_1 to define the "reference date" based on the inDate context variable with the following expression:

TalendDate.addDate(context.inDate, "yyyyMMdd", -90, "dd")

tFileList_2 to get file list (no comment)

tSetGlobalVar_3 to compute the "file date" base on the current filename with the following expression:

((String)globalMap.get("tFileList_2_CURRENT_FILE")).replaceAll("^.*\\.D", "")

If trigger is defined with the following expression:

((String)globalMap.get("referenceDate")).compareTo((String)globalMap.get("fileDate")) <= 0

Note: we can use String.compareTo() because of the date format (yyyyMMdd).

 

tFileCopy to move the current file into the archived folder:

0683p000009M88y.png

Anonymous
Not applicable
Author

Hi,

 

attaching the job component by component.

Now the job runs successfully but file is not getting copied ( there are files that are more than 90 days old in the source location) to the archive path.

 

Not getting what has gone wrong. 


archive_file.docx
TRF
Champion II
Champion II

Do you some files successfully archived?
Can you share filename for files not archived?
Anonymous
Not applicable
Author

Hi,

 

No files got archived even when there were files matching the criteria(greater than 90 days).

Attaching the files from the path along with.(for testing purposes i have created touch files which is why all are showing up as 0 KB).

 

Thanks.


archive_file.docx