Datamapper script execution()

Hello,
I try to use a Datamapper the execute() function in an action step. I want to execute a cmd action and it worked one time but now I only get com.objectiflune.datamining.scripting.utils.ExternalProgram@719b02c3 as logger.info output in messages pane.

If I copy that log message I will get the following:

INFO [18 Nov 2022 09:19:38,125][main] com.objectiflune.scripting.engine.OLErrorReporter.processLogMessage(OLErrorReporter.java:-1)[COMPONENT=Skript-Logger][SOURCE= - Zeile 35] com.objectiflune.datamining.scripting.utils.ExternalProgram@8a47362

Example script:

if(record.index == 1){
  var myCommand = 'net use A:';
  var cmdResponse = execute(myCommand);
}

I also wonder why every script is executed twice…

Any advice how to use the execute() function correctly in a Datamapper action step would be great! :slight_smile:

Hi thomas

Did you find an answer for this elsewhere or do you still need assistance?

regards

Hi Alex,

I did not find an answer for the Datamapper. Meanwhile I have created a workflow process to do the action. But it would be great if I could implement my solution in Datamapper, because I want to deploy this check (see requirement below) to all clients without an extra workflow process.

Specifically, I want to address GhostScript with appropriate commands and store the return information (stdOut) in a data field.

But if I understand it correctly the execute() function can only execute a program, without specifying any parameters.

My requirement:
I want to examine a certain area in the loaded input PDF in Datamapper and make a visual check if this area is free (no colored pixels contained). With GhostScript such a check can be realized.

You could call a batch file instead of calling the application itself.
So for instance, you could create a file named C:\test\mybatch.bat containing the following command:

dir c:\somefolder\*.pdf: >> C:\test\results.txt

If you run that batch file manually from the Windows command line, it will create a file named results.txt in the c:\test folder, containing the names of all PDFs in the c:\somefolder folder.

You can then use the following to run the batch file from inside the DataMapper:

if(record.index == 1){
  var myCommand = 'c:\\test\\mybatch.bat';
  var cmdResponse = execute(myCommand);
}

Obviously, the batch file could contain as many commands as you want.

Note that you can pass parameters to the batch file (which are addressed as %1, %2, %3, etc. inside the batch file). This allows you to dynamically modify the command to execute.

So your batch file could contain:

dir %1\*.pdf: >> C:\test\results.txt

and your JS code in the datamapper would look like this:

if(record.index == 1){
  var myCommand = 'c:\\test\\mybatch.bat C:\\someotherfolder';
  var cmdResponse = execute(myCommand);
}

This allows the DataMapper to specify, in this example, from which folder it wants the PDF listing.