web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to specify the filepath and filename dynamically in Job?

(0) ShareShare
ReportReport
Posted on by 1,385

Hai Friends,

In Job, I have used the following code line to generate a text file in which the file path is hard-coded.

TextIo f = new TextIo(@"D:\AX\input.txt", 'w', 0);

But I want to set it dynamically. For that I have created a new table "AAAA" and form named "BBBB" is bounded to that table. The form BBBB contains...

1. Input Filename,

2. Input Filepath

3. Output Filename

4. Output Filepath

On running the Job, I need to get the combination (concatenation) of Input Filepath + Input Filename + .txt and the text file should get stored in the specified folder.

How to write the equivalent code to: TextIo f = new TextIo(@"D:\AX\input.txt", 'w', 0);?

Thanks,

Aarvi.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Lars Morgenroth Profile Picture
    265 on at

    - select the values from your parametertable.

    - declare strings inputFilePath and OutputFilePath

    - fill them with values from the table

    - check if files / paths exists

    - you do  f = new TextIo(outPutFilePath, 'w', 0);

  • Suggested answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    There are many options and your choice depends on how "smart" it should be. You just have to be careful about joining path together correctly and not to introduce any invalid characters (e.g. \t). This is one of possible ways:

    str filePath = @'c:\temp';
    str fileNameWithoutExt = 'x';
    #File
    ;
    info(filePath + #FilePathDelimiter + fileNameWithoutExt + #txt);

    You might also benefit from using System.IO.Path::Combine().

  • arviax Profile Picture
    1,385 on at

    Thanks Martin and Lars for your replies!

    Lars, Can you explain more in detail. Because I am not getting the output when I followed your way. I guess I am doing something wrong somewhere.

    Martin, I should not define the File path in the coding directly. I will be giving the filepath and filename in a seperate table. I need to concatenate filepath , filename and extension in the code by giving the variable name.

    Thanks,

    Aarvi.

  • Lars Morgenroth Profile Picture
    265 on at

    Could you please provide a code snipped of your job ?

    That would simplify things

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    @Arviax: Just fill variables filePath and fileNameWitthoutExt with your values or replace them completely. I didn't think that it's needed to mention that.

    You know how to read a field value, don't you?

  • arviax Profile Picture
    1,385 on at

    Lars,

    I gave below values for the fields in the FolderPathtable:

    Input File name: input

    Path: D:\AX\

    Output File name: output

    Path: D:\AX\

    Code:

    static void ABC(Args _args)

     {  

       FolderPathTable folderPathtable;

       str inputFilepath = folderPathtable.InputDirectory;

       str inputFilename = folderPathtable.InputFilename;

       str outputFilepath = folderPathtable.OutputDirectory;

       str outputFilename = folderPathtable.OutputFilename;

       str inputFileDir = inputFilepath + inputFilename. '.txt';;

       str outputFileDir = outputFilepath + outputFilename + '.txt';

       TextIo f = new TextIo(inputFileDir, 'w', 0);

       ;

    }

  • Lars Morgenroth Profile Picture
    265 on at

    you do not select the values of folderPathtable ;-)

    you first have to select the values from the table and then you can assign the results to variables.

  • arviax Profile Picture
    1,385 on at

    Lars,

    Do you mean like this..?

    static void ABC(Args _args)

    {

     FolderPathTable folderPathtable;

     str inputFileDir, outputFileDir;

     inputFileDir = folderPathtable.InputDirectory + folderPathtable.InputFilename + '.txt';

     outputFileDir = folderPathtable.OutputDirectory + folderPathtable.OutputFilename + '.txt';

     TextIo f = new TextIo(inputFileDir, 'w', 0);

     ;

    }

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    You never read any data from database, therefore folderPathTable is always empty. Use a select statement to actually get data from database.

    If you debug the code, it should be obvious that you're working with empty values.

  • Lars Morgenroth Profile Picture
    265 on at

    At the moment your variable folderPathtable contains only the structure of the table FolderPathTable.

    To get values in it, you have to do a select on the table like:

    select firstonly folderPathtable.

    you can have a look at that link:

    msdn.microsoft.com/.../aa848113%28v=ax.50%29.aspx

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans