Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] using context variable in custom routine

[font=Verdana, Helvetica, Arial, sans-serif]Hi Talend Pros,

How can i use context variable into
[/font] custom routine ??


i tried context.getPropety("paramName") but it does nt work .

Thanks

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

OK. At the moment, all your routine will do is print the path with the value of a "param" variable to the terminal. You need to change the signature of the routine to something like below....

public static void myRoutine(String param) {
    String   path = "/home/data/"+param ;
            System.out.println(path);
            }


This will be called like below....
Myroutine.myRoutine(context.paramName);

I assume that you just want the value to be printed to the terminal and you don't want to use the value in the job. If you want to use the value in the job, you need to have a method return other than "Void". Check out how to write methods in Java.

View solution in original post

5 Replies
Anonymous
Not applicable
Author

You have to supply it to the routine when you call it within the job. When you supply it, you should do it as below.....

routines.YourRoutines.youRoutine(context.paramName)
Anonymous
Not applicable
Author

i have a String into my routine 
String   path = "/home/data/sofinco" ;
i want to replace sofinco by a param from the context . .
##################Myroutine .java######################
public static void main() {
String   path = "/home/data/"+param ;
System.out.println(path);
}
########################################
i call my routine within the job as below : Myroutine.main();



how i can do it please and thnk you 
Anonymous
Not applicable
Author

You routine should not be called main.
In the example you were given, your routine may be something like this.
public void youRoutine(String paramName) {
System.out.println(paramName);
}
Anonymous
Not applicable
Author

OK. At the moment, all your routine will do is print the path with the value of a "param" variable to the terminal. You need to change the signature of the routine to something like below....

public static void myRoutine(String param) {
    String   path = "/home/data/"+param ;
            System.out.println(path);
            }


This will be called like below....
Myroutine.myRoutine(context.paramName);

I assume that you just want the value to be printed to the terminal and you don't want to use the value in the job. If you want to use the value in the job, you need to have a method return other than "Void". Check out how to write methods in Java.
Anonymous
Not applicable
Author

Thanks everyone i did it 0683p000009MACn.png