Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

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

1 Accepted Solution
Vapsy
Correct answer by
Employee
Employee

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

View solution in original post

3 Replies
Vapsy
Correct answer by
Employee
Employee

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

View solution in original post

mithiltaneja
Level 2
Level 2

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 3
Level 3

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

Regards,

Ankur A.