Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
dattasud
Contributor III
Contributor III

How to dynamically pass or select the context variable of file type when run through build batch file?

Hi All,

In my job, I have tFileInputDelimited which loads the context variables. The file is located in my local directory.

How can I configure the path dynamically so that when I run the build using batch file through command prompt, I can pass the tFileInputDelimited dynamically. I am doing this because I will be running the build in target server.

How can I give relative path to tFileInputDelimited, so that it can read the file from same directory?

 

 

Labels (2)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

Remove tFileInputDelimited and tContextLoad from your job.
Define a new context variable (contextFilepath for example) with the desired value path for each context.
Go go job tab, then extra and untick option "Use Project Settings", tick "Implicit tContextLoad", tick "From file" and enter "context.contextFilepath" into the associated field.
At runtime, on command line add "--context=theContextYouWant" to start the job within the desired context or add "--context_param contextFilepath=thePathYouWantToUse" to use the context file you want.

View solution in original post

5 Replies
dattasud
Contributor III
Contributor III
Author

I have used context variable of type File with prompt and configured in the File name/Stream of the tFileInputDelimited. 

 

When I run the job through Talend Open Source, I get the prompt to select the file from my directory. How can I pass the path when I run the batch file?

I copied the tFileInputDelimited file in same location of the batch file and passed with batch execution but getting file not found error for the file whose path is present in the input file then setting it to context variable.

Please help!!

0683p000009M9Zr.jpg0683p000009M9bJ.jpg0683p000009M9dA.jpg

TRF
Champion II
Champion II

Remove tFileInputDelimited and tContextLoad from your job.
Define a new context variable (contextFilepath for example) with the desired value path for each context.
Go go job tab, then extra and untick option "Use Project Settings", tick "Implicit tContextLoad", tick "From file" and enter "context.contextFilepath" into the associated field.
At runtime, on command line add "--context=theContextYouWant" to start the job within the desired context or add "--context_param contextFilepath=thePathYouWantToUse" to use the context file you want.
dattasud
Contributor III
Contributor III
Author

Many thanks for the solution @TRF .


I also did something similar to solve the problem. I removed the tfileinput and contextload from my job. Now I just have my context variables. After I build the job, i navigate to the context/Default.properties and added the value of my context variables. I checked when I ran the build, it was showing the context=Default
That way I am able to pass my variable values.

 

I will use your solution to implement using implicit tContextLoad in my job.

TRF
Champion II
Champion II

That's the way context work by default.
What I suggest is a more advanced solution.
Imagine you have 10 jobs whith 3 different context. If you want to change the value for 1 variable used by all jobs and context, you have to modify 30 context files. Right?
With the proposed solution you just have to modify 3 files. Also, you don't have to define the value for each variable within the Studio. You can do it from outside and it's often more confortable.
I strongly recommand to think about this way to operate with context.
dattasud
Contributor III
Contributor III
Author

Yes, it is more advanced and easy to configure.