Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] How to Receive a Date context parameter through the shell script?

If I have a context parameter named "id" of type Integer, I can set it from the command line in the following manner:
Test_0.1.sh --context_param id=100
How would I go about passing a date through the shell script using the --context_param argument? Does Talend have a particular format string it would like to see?
Using a context parameter named "dt" of type Date, I tried the following:
Test_0.1.sh --context_param dt=2014-10-15
But in my program I see that it is null.
Regards,
Matthew
Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

got it 0683p000009MACn.png
trying to put a default date to my context give me the clue .
0683p000009MB1x.png
you can put a "date' ( not really Date type ) with his pattern in the java commandline : (something like)

C:\Talend\test\boolParam_0.1\boolParam>boolParam_run.bat --context_param datej="
yyyy-MM-dd HH:mm:ss;2014-10-16 12:18:33"

So you can 0683p000009MA9p.png
regards
laurent

View solution in original post

8 Replies
Anonymous
Not applicable
Author

hi mmoisen,
you are not 'passing a date' to your script.
it's just a suite of caraters that will be be seen as a String in java. So if you have to manage Date type in your Talend Process, you'll have to convert string in Date before.
I often read a date as a string until I have to use Date methods to do some calculation (ex : add a date). Otherwise keep it in String.

TalendDate.parseDate("dd-MM-yyy",context.dateparam)

regards
laurent
Anonymous
Not applicable
Author

hi mmoisen,
you are not 'passing a date' to your script.
it's just a suite of caraters that will be be seen as a String in java. So if you have to manage Date type in your Talend Process, you'll have to convert string in Date before.
I often read a date as a string until I have to use Date methods to do some calculation (ex : add a date). Otherwise keep it in String.

TalendDate.parseDate("dd-MM-yyy",context.dateparam)

regards
laurent

Hi Laurent,
In the case of a context variable I've defined as a Long or Integer, Talend apparently converts it for me into the correct data type. However for Date your conclusion is correct as far as I can tell-- I'll convert it into a Date before utilizing it.
Thanks,
Matthew
Anonymous
Not applicable
Author

I've defined as a Long or Integer, Talend apparently converts it for me into the correct data type

??? 0683p000009MACn.png
if you have define your data as Long or Integer, you have to convert explicitly it into Date to have a Date, no ?
otherwise you'll have
Type mismatch: cannot convert from Integer to Date
Anonymous
Not applicable
Author

I mean to say, if I've defined a context variable as a Long, and I pass the value via test_1.0.sh --context_param long_id=123, Talend appears to convert it from Long to String for me.
But if I've defined a context variable as a Date, it won't convert from String to Date for me.
Anonymous
Not applicable
Author

but in '--context_param long_id=123', 123 is not a String or a Long or any other java type 0683p000009MA9p.png
outside java (talend) you are not manipulating java type.
a value for a param context , coming from shell script or a config.ini will always deen as a String (java type) in your application.
Anonymous
Not applicable
Author

but in '--context_param long_id=123', 123 is not a String or a Long or any other java type 0683p000009MA9p.png
outside java (talend) you are not manipulating java type.
a value for a param context , coming from shell script or a config.ini will always deen as a String (java type) in your application.

Hey Kzone,
I've tried it with Long, Integer, and Boolean. Talend must be smart enough to convert it from a String to the appropriate java type.
For example, I have a job called TestCommandLineBoolean, with a context variable named "is_bool" of type Boolean

and one tJava with the following code:

if (context.is_bool != null) {
    if (context.is_bool) {
        System.out.println("is_bool is true");
    } else {
        System.out.println("is_bool is false");
    }
} else if (context.is_bool == null) {
    System.out.println("is_bool is null");
} else {
    System.out.println("is_bool is neither!");
}

If I run it without passing a context parameter, is_bool defaults to false:
0683p000009MBFT.png
If I run it passing in "true", "True", or "TrUe", is_bool is set to true:
0683p000009MAkY.png
0683p000009MAkY.png
0683p000009MBFY.png
However, If I run it passing in "truetrue", "false", or "abcd", is_bool is set to (or remains) false:
0683p000009M8C4.png
0683p000009M8C4.png
0683p000009M8C4.png
So Talend appears to be converting it for me.
I would be curious to know if it also does the same for Dates, given it is entered in the proper format.
Regards,
Matthew
Anonymous
Not applicable
Author

you're right for boolean

try {
                context.chooce = routines.system.ParserUtils
                        .parseTo_Boolean(context.getProperty("chooce"));

as declared as Boolean, Talend try to parse context flow (String) in a boolean.
Assign null at exception :

catch (NumberFormatException e) {
                context.chooce = null;
            }
Anonymous
Not applicable
Author

got it 0683p000009MACn.png
trying to put a default date to my context give me the clue .
0683p000009MB1x.png
you can put a "date' ( not really Date type ) with his pattern in the java commandline : (something like)

C:\Talend\test\boolParam_0.1\boolParam>boolParam_run.bat --context_param datej="
yyyy-MM-dd HH:mm:ss;2014-10-16 12:18:33"

So you can 0683p000009MA9p.png
regards
laurent