Troubleshooting post processor script

I have a post processor script that performs a SQL insert into a customer’s MySQL table (not Connect’s instance, a separate one). The insert values I expected are not there, so I am attempting to use logger.info() to inspect the values I’m attempting to insert. Where can I find the logger messages in the Connect logs? The data mapper log I inspected does not show it.

Have you checked your overall logging setting in the Preferences? They must be set to either info, debug, trace or all in order for the logger.info() calls to appear in the logs.

The log level is set to “Info”

I tried it here with a very simple script and it works just fine, so perhaps your script is not executing up to the log() line. Test it again, but with this one-line script:

logger.info("There are "+data.records.length+" records in this job.")

In the Datamapperengine.log file, search for [COMPONENT=Script logger], you should see a log entry similar to this:

[2020-08-07 08:07:50,709] INFO [IPC Input] com.objectiflune.scripting.engine.OLErrorReporter.processLogMessage(OLErrorReporter.java) [COMPONENT=Script logger][SOURCE=Count Records - line 1] There are 15 records in this job.

Just ran in debug mode and did a search of all files in the Connect\Log\Datamapperengine directory. 0 hits. Maybe it only works when running live?
Or perhaps this perhaps an issue that was previously solved? the end user has v2018.2

The messages are only sent to the logs when running live (i.e. through the Connect Service), but you can still do that while running your Workflow process in debug mode.

From the DataMapper UI itself, messages are only displayed on-screen and not stored anywhere.

As for the customer’s version, not sure if it has anything to do with it but they should really upgrade to the latest version.

Thanks the search tip worked. I found the entries in their log files for a different user, not the one I was told to check.

My end user wants me to write data to a file from the post processor script on any exceptions where I couldnt update his table with a valid value (where policy number is empty for example).
If I use createTmpFile() where does this file get created? In the Connect temp folder under C:\Users[user acct]\Connect\Temp ?

You can get the full path to the file with getPath():

var tmpFile = createTmpFile();
var fullPath = tmpFile.getPath().

thanks Phil, that helped me locate the file in C:\Users[user acct]\AppData\Local\Temp. How would I rename it since I cant specify a filename?

There is no rename function, but you can use:

copyFile(fullPath,"C:/tests/MyFile.txt");
deleteFile(fullPath);

thanks, one last question on this because I have it working but only creating one log file, overwriting the previous one, is there a way to append to the file instead of overwriting it? An example is very much appreciated.

https://help.objectiflune.com/en/pres-connect-user-guide/2020.1/#datamapper/API/Function_openTextWriter.htm

Hi Phil,

Is there any way to check if a file exists first in the data mapper API before calling openTextWriter so the appending flag can be set appropriately?

There is no FileExists() method per se, but you can use the following piece of code to achieve the same results:

try{
	let testFile = openTextReader("C:/tests/MyTestFile.txt");
	testFile.close();
	// add code here to open file in APPEND MODE
} catch (e) {
	// add code here to open file in CREATE MODE
}