OL Learn

Dynamic Image (Contain Field)

May i know can i set display the dynamic image when the field name CONTAIN the value of the value but not EUQAL?

And also how can I display all images in a folder that contain that value? (There can be more than one image contain that number.)

Hi @ceci_cheung,

As far as I know it’s not possible to pickup a image source from within a Connect Template without knowing the compleet filename.

A option is to make on the PlanetPress Workflow side use of the Folder Listing plugin to know which know which files the “ImageFolder” folder does contain. After executing the Folder Listing plugin you can for example execute the XML/JSON Conversion plugin to convert the XML output file of the Folder Listing plugin to a JSON file. And after that you can create a JavaScript Array of all the filenames and parse this Array value via a Local Variable to your Data Mapping Configuration file as for example a Runtime Parameter:

  1. Folder Listing plugin:
  • Input folder: C:\ImageFolder
  • Sorted by: Name
  • File mask: *.png
  1. XML/JSON Conversion plugin:
  • Automatic detection: “unchecked”
  • XML to JSON: “selected”
  1. Run Script plugin:
    JavaScript code (example):
var jobFileContent = Watch.ExpandString("%c");
var obj = JSON.parse(jobFileContent);
var fileNames = [];

if (typeof obj.files !== "undefined") {
	if (typeof obj.files.folder !== "undefined") {
		if (obj.files.folder.file instanceof Array) {
			for (var i = 0; i < obj.files.folder.file.length; i++) {
				var fileName = obj.files.folder.file[i].filename;
				if (typeof fileName !== "undefined") {
		} else if (obj.files.folder.file instanceof Object) {
			var fileName = obj.files.folder.file.filename;
			if (typeof fileName !== "undefined") {

Watch.SetVariable("fileNames", JSON.stringify(fileNames));
  1. Folder Capture plugin (to pickup the input file of the Execute Data Mapping plugin)
  2. Execute Data Mapping plugin > Runtime Parameter: fileNames, Value: %{fileNames}

In this case you’ve to make use of a Standard Script in your Connect Template to check if there is a file(name) which contains the record field “PatientID”.

P.S. Please note that I haven’t tested this completely. And please note that the JavaScript code has been tested in version 2021.1.2 of PReS Connect Workflow.

Hi @Marten

Thanks for reply.
So is it step 1-5 is actually obtaining the image file name from a folder, and mapping the filename list into the data??
And i am still not very understand how can designer know how many images need to displayed in template? Cause one dynamic image only show one image?

Hi @ceci_cheung,

Step 1-3 obtains the file names of the images which does exist in the given directory and add these filenames to the Local Variable “fileNames”.

In step 4 you’ve the option to assign the value of the Local Variable “fileNames” to a Runtime Parameter. And in the Data Mapping Configuration file you’ve the option to assign the value of this Runtime Parameter to a record field.

And when you would like to add all the images, of which the filename does contain the value of the record field “PatientID”, below each other to your Template then you can make use of for example the following JavaScript code:

Standard Script
Selector: span#example

var field = "";
var patientId = "";
var result = "";
var fileNames = [];

field = record.fields["filenames"];
patientId = record.fields["patientID"];

if (field !== "" && patientId !== "") {
	fileNames = JSON.parse(field);
	if (fileNames instanceof Array) {
		for (var i = 0; i < fileNames.length; i++) {
			if (fileNames[i].indexOf(patientId) >= 0) {
				result += "<img src=\"file:///C:/path/to/" + fileNames[i] + "\" style=\"width: 300px; height: 200px;\">";

Where span#example is just a placeholder like:

<span id="example"></span>

Hi @Marten Sorry for replying you so late.

I have finished step 1-3 and
I got some of the questions when following you suggestion:

  1. Seems that i cannot add any runtime parameter in the data mapper configuration, is that any setting i have to do? (The ‘+’ is deemed)
  2. And after assigned value in workflow, do i need to do any setting in template before using automation.variable to extract the image file name??

Thanks so much and appreciate for your explanation.

Hi @ceci_cheung,

You’ve the option of adding a Runtime Parameter via the Preprocessor Step (the first Step shown in the Steps window) or via the Parameters panel by creating or editing a Data Mapping Configuration file via the Connect Designer. After adding the Runtime Parameter to the Data Mapping Configuration file, and after uploading the customized Data Mapping Configuration file to Workflow, the Runtime Parameter will be available in the Runtime Parameter list of Execute Data Mapping plugin.

After adding the Runtime Parameter to the Data Mapping Configuration file you’ve the option to assign it’s value to a record field by using the JavaScript code automation.parameters or you can use it directly in for example a Standard Script in a Connect Template by using the JavaScript code merge.template.parameters.