Unanswered question

How can I access File Variables metadata (like lastmodifieddate) from within Javascript action

Want to check couple of metadata from a variable file in javascript action to decide if update that file or not.

Michel T.
Michel T.

Michel T.

Level
0
45 / 100
points

Answers

Fousseyni B.
Fousseyni B.

Fousseyni B.

Level
2
1014 / 2000
points

Hello Michel

I don't know if it possible to get file metadata from a javascript action on Neoload. Indeed, even browsers have to implement FileReader interface for a javascript code to access file on the client.

But you can use two files : the one you already have and a second one containing the metadata of your first file. And you just have to fetch those metadata thanks to a shell script action executed by Neoload at some point of your test.

So you will check in your second file variable the state of your first file.

Best Regards,
Fousseyni B.

Michel T.
Michel T.

Michel T.

Level
0
45 / 100
points

Thanks Fousseyni, actually I find out that code below works for my purpose, the only thing that I am struggling now is how to get project path folder (variables folder)

var file = new java.io.File("{folder}\\variables\\datafile.txt");
logger.info(new Date(file.lastModified()));

Fousseyni B.
Fousseyni B.

Fousseyni B.

Level
2
1014 / 2000
points

Hello Michel,

You can copy your file containing your variable inside the "custom-resources" folder (Neoload installation folder) without any subfolders otherwise it won't work. And you will access it from ${NL-CustomResources} or using a javascript : context.variableManager.getValue("variable")

Best Regards,
Fousseyni B.

Michel T.
Michel T.

Michel T.

Level
0
45 / 100
points

Hi again, one more question... but before that let me contextualize you what I am trying to do: I want to have a file variable that has as content a returned query from SQL, but I would like to validate if that data is old enough to re-run a query and update content. So, my strategy is having this variable file, check with javascript if it is old enough, if so I run again a SQL statement and write/update the same file.
Said that, my question is: NL-CustomResources will return a path inside AppData, solves one of my problems, but now I still need to have a way to identify the project folder path to write/update the original file (in variables or custom-resources folder inside my project) with new content.

Michel T.
Michel T.

Michel T.

Level
0
45 / 100
points

In fact, if that SQL variable had a validation like, "is this file content older than 1 month? THEN run again the sql statement, ELSE, do not run sql query and keep using the same temp content file" it will do the same that I am trying to achieve