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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
ar7368
Contributor
Contributor

File Transfer

Hi,
I have a job to modify filenames of files(pdf) from source with static data inserted in the fourth component of file name such that it will have the following format
TAC_CAT_time/date_Op2_uniqueID.pdf. The filenames will already contain TAC_CAT_DATE_unique ID.pdf. thus Op2 (case sensitive) is missing. The TAC and CAT components are 8 and 9 characters long respectively. I have figured out all of the above, except that when the MRN or HAR are not within 8 or 9 characters long i need to generate a error. Sometimes these components are keyed in wrong by users. How do I filter these files? to generate a email.
So in effect the 28th character in my filename needs to "_".
Labels (2)
22 Replies
Anonymous
Not applicable

Hi
So in effect the 28th character in my filename needs to "_".

According to your requirement, we can create part of your job as follow.
Regards,
Pedro
ar7368
Contributor
Contributor
Author

Hi Pedro,
Sorry its the 27th character, if you start from 0. So right now I have the following code in my tfilecopy component
---------------
((String)globalMap.get("tForeach_1_CURRENT_VALUE")).substring(0,19)+((String)globalMap.get("tForeach_1_CURRENT_VALUE")).substring(23,27)+((String)globalMap.get("tForeach_1_CURRENT_VALUE")).substring(19,23)+"_"+"Op2"+"_"+((String)globalMap.get("tForeach_1_CURRENT_VALUE")).substring(28,((String)globalMap.get("tForeach_1_CURRENT_VALUE")).length())
----------------
So should I be using tIterateflow instead of tforeach?. Will try as you suggested.
Thanks,
ar7368
Contributor
Contributor
Author

Hi Pedro,
The job ran as you suggested. But in the destination folder I can see just one file that is transferred. The rest of the files are missing eventhough the job says it moved 11 files which is the correct number. I'm missing something here. Please help.
Thanks,
Anonymous
Not applicable

Hi
From this image, we are sure that tFilerRow works fine.
It seems that there is something wrong in tFileCopy.
You'd better recheck it.
Regards,
Pedro
ar7368
Contributor
Contributor
Author

Hi Pedro,
I just can't isolate the problem, Following are the screens when I use tlogrow and alternatively when I use tfilecopy
The destination filename code I have on Tfilecopy is as follows
----------------------------
((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(0,19)+((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(23,27)+((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(19,23)+"_"+"Op2"+"_"+((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(32,((String)globalMap.get("tFileList_1_CURRENT_FILE")).length())
-------------------------------
When Tfilecopy is used with Tfilter will the files transfer or is Tfilter used to just list the filtered files but no physically move them?
ar7368
Contributor
Contributor
Author

Sorry that is not the case. Its 5 parts before the insertion of "Op2" a constant. The destination files need to have 6 parts in total.
janhess
Creator II
Creator II

I've got this routine for splitting strings into parts on a delimiter.
    /**
* reverseIt() Reverses a string.
*
* {talendTypes} String
*
* {Category} Ncl_routines
*
* {param} string ("fred") input: the string to be reversed
*
* {example} reverseIt("fred") # derf
*
*/
public static String reverseIt(String source) {
int i, len = source.length();
StringBuffer dest = new StringBuffer(len);
for (i = (len - 1); i >= 0; i--)
dest.append(source.charAt(i));
return dest.toString();
}
/**
* anyWord() finds a word in a string based on a delimiter and the number of the word required.
* It can search forwards or backwards depending on whether the number of the word is positive or negative.
*
* {talendTypes} String
*
* {Category} Ncl_routines
*
* {param} string("hello Example") input: The string need to be parsed.
*
* {param} string(" ") input: the delimiter
*
* {param} int(0) input: the number of the word to return - 0 is first occurrence -1 is the last.
*
* {example} anyWord("hello Example"," ",0) # hello
*/

@SuppressWarnings("finally")
public static String anyWord(String message, String delimiter, Integer number ) {
String returnString = null;
Integer reverseit = 0;
try {
if (number < 0) {
message = Ncl_routines.reverseIt(message);
number = -1 - number;
reverseit = 1;
}
if (delimiter.equals(" ")) {
String[] starwords = message.split (" ");
returnString = starwords;
}
if (! delimiter.equals(" ")) {
String[] starwords = message.split ("\\" + delimiter);
returnString = starwords;
}
if (reverseit == 1) {
returnString = Ncl_routines.reverseIt(returnString);
}
} catch (ArrayIndexOutOfBoundsException e) {
returnString = "";
} finally {
return returnString;
}
}
}

So for your string you could have
anyWord(((String)globalMap.get("tFileList_1_CURRENT_FILE")),"-",0) + "_" + anyWord(((String)globalMap.get("tFileList_1_CURRENT_FILE")),"-",1) + "_" +
anyWord(((String)globalMap.get("tFileList_1_CURRENT_FILE")),"-",2) + "_" +
anyWord(((String)globalMap.get("tFileList_1_CURRENT_FILE")),"-",3) + "_" +
"Op2_" +
anyWord(((String)globalMap.get("tFileList_1_CURRENT_FILE")),"-",4)

This saves worying about the length of each component.
"
ar7368
Contributor
Contributor
Author

Ok the third component is a date which is in mmddyyyy, I need it in yyyymmdd. So how do i deal with that?. I am currently using the following in the 3rd component.
-----------
((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(23,27)+((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(19,23)
-----------
Could I use the one above in the 3rd part of your code ?
janhess
Creator II
Creator II

Do the substring on the anyWord.