Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi Expert,
I am using a t_OutputExcel component to write data in a folder. In the file output file name, I am using multiple context variable to define the directory as well as file name.
I am using a talend getdate function to get the month :
TalendDate.formatDate("MMyy",(TalendDate.getFirstDayOfMonth(TalendDate.addDate(TalendDate.getCurrentDate(),-1,"MM")))).toString()
The Hardcoded function works correctly but when I assign the same value in the context variable It is giving me an error:
[statistics] connected
[FATAL]: talend_default.tFileOutputExcel_1 \\me\d\2\E\D\l_1218-TalendDate.formatDate("MMyy",(TalendDate.getFirstDayOfMonth(TalendDate.addDate(TalendDate.getCurrentDate(),-1,"MM")))).toString().xlsx (The filename, directory name, or volume label syntax is incorrect)
Exception in component tFileOutputExcel_1
java.io.FileNotFoundException: \\me\d\2\E\D\l_1218-TalendDate.formatDate("MMyy",(TalendDate.getFirstDayOfMonth(TalendDate.addDate(TalendDate.getCurrentDate(),-1,"MM")))).toString().xlsx (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at org.talend.ExcelTool.writeExcel(ExcelTool.java:294)
I have two options: ( I preffer option 2 just defining the Integer value -1)
1. Is using the full function inside the context: (TalendDate.getFirstDayOfMonth(TalendDate.addDate(TalendDate.getCurrentDate(),-1,"MM")))).toString()
2. Using only the -1 to define the month and then call it :
context.NM_END_MMYY >type int > value -1
(TalendDate.getFirstDayOfMonth(TalendDate.addDate(TalendDate.getCurrentDate(), + context.NM_END_MMYY +,"MM")))).toString()
Currently, I am coding it like this:
File Name::
context.NM_MSK + TalendDate.formatDate("MMyy",(TalendDate.getFirstDayOfMonth(TalendDate.addDate(TalendDate.getCurrentDate(), -2,"MM")))).toString() + "-" + context.END_MMYY + ".xlsx"
Hi,
you can not use functions as a context value - this is no doubt
you must use context for store fixed part of name + function for define variable part of the name
Well, you can't use functions in the Contexts section of the Studio, but you can use functions if you set the Context at the beginning of the job in a tJava or similar. If the first component of the job is a tJava with the expression shown in the first screenshot, then it should work OK.
context.MyContextVariable = routines.SomeFunction(someParam);
That would work.
Hi,
Thanks for your response. Can you explain the solution a little bit more.
In the actual job I am using a parameter text file to load the context values. In my job I am not hard coding any context value. I am only defining the context name and call it from a text file.
So how I can define the numeric (-2) value in a context variable?
TalendDate.formatDate("MMyy",(TalendDate.getFirstDayOfMonth(TalendDate.addDate(TalendDate.getCurrentDate(),-2,"MM")))).toString()
Because I don't want to touch the job in future, rather I will change the context variable value in the text file.
I will appreciate if you can give me an example.
My solution was simply to take your complicated code and apply it in a tJava component at the beginning of your job. So, using some code you used in your previous post, this is how I would assign the value to a context variable in a tJava......
context.ContextVariableName = TalendDate.formatDate("MMyy",(TalendDate.getFirstDayOfMonth(TalendDate.addDate(TalendDate.getCurrentDate(),-2,"MM")))).toString();