How to read the first line of a text document in adobe campaign via javascript coding? | Community
Skip to main content
Level 2
August 10, 2017
Solved

How to read the first line of a text document in adobe campaign via javascript coding?

  • August 10, 2017
  • 3 replies
  • 3036 views

Hi, please help me with this.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by vraghav

Hi ,

The following code will print all the lines from a file into the workflow journal logs.

You can customize it to read only the first line

var file = new File( fName );

  var arr = [];

  file.open();

  try

  {

    for each(var line in file)

    {

      arr.push( line );

    }

    for ( var i = arr.length - 1; i >= 0; i-- )

      logInfo(arr[i]);

    logInfo( "###=====  " + fName );

  }

  finally

  {

    file.close();

  }

Hope this helps.

Regards,
Vipul

3 replies

vraghav
Adobe Employee
vraghavAdobe EmployeeAccepted solution
Adobe Employee
August 10, 2017

Hi ,

The following code will print all the lines from a file into the workflow journal logs.

You can customize it to read only the first line

var file = new File( fName );

  var arr = [];

  file.open();

  try

  {

    for each(var line in file)

    {

      arr.push( line );

    }

    for ( var i = arr.length - 1; i >= 0; i-- )

      logInfo(arr[i]);

    logInfo( "###=====  " + fName );

  }

  finally

  {

    file.close();

  }

Hope this helps.

Regards,
Vipul

Level 2
August 10, 2017

Hi Vipul,

Thanks for the code.

var file = new File( fName );

Can this code be modified to use a file downloaded from the file collector activity which is in temp db.

Could you please help me with that?

_nkur
Level 2
August 10, 2017

Yes, it is just use "vars.filename" instead of fName

Regards,

Ankur A.