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") {
					fileNames.push(obj.files.folder.file[i].filename);
				}
			}
		} else if (obj.files.folder.file instanceof Object) {
			var fileName = obj.files.folder.file.filename;
			
			if (typeof fileName !== "undefined") {
				fileNames.push(obj.files.folder.file.filename);
			}
		}
	}
}

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.

1 Like

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;\">";
			}
		}
	}
}
results.replaceWith(result);

Where span#example is just a placeholder like:

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

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.

1 Like

Hi @Marten,

But if i am using jobinfo to store the value, is it no need to set the parameter in designer/workflow?
Is it what i have to do is to create a field and return the value lie below? But I am failed to return the value (The value in ImageName is still empty.)

Hi @ceci_cheung,

Please make sure that you assign a default value to the Job Info Variable or Runtime Parameter if you would like to make use of the Job Info Variable or a Runtime Parameter on the Connect Designer side, otherwise it will still be empty when you open the Data Mapping Configuration in the Connect Designer application.

1 Like

hi @Marten
I did assign value to jobinfo9 but still got no value. :thinking:

Hi @ceci_cheung ,

You’re missing an important step. You first have to convert the JavaScript Object to a String before assigning it to the Job Info Variable 9, you can do this by making use of the JSON.stringify() function, like for example:

Watch.SetJobInfo(9, JSON.stringify(fileNames));

Hi @Marten Thanks for reminding. I replaced Watch.SetJobInfo(9, fileNames); to Watch.SetJobInfo(9, JSON.stringify(fileNames)); But still got no value like below:


Any idea ?

Hi @ceci_cheung,

That’s because the Job Info Variable or Runtime Parameter doesn’t have a value when you open the Data Mapping Configuration in the Connect Designer.

When you would like to assign a value to it on the Connect Designer side then you can add a value to the Default Value input field. As for Runtime Parameter you can do this by creating a new Runtime Parameter or by editing a existing one via the Parameters pane and as for Job Info Variable you can do this by adding a value to one of cells the Default Value column, depending on which Job Info Variable is involved.

Hi @Marten

But can i get the value i assigned in jobinfo9 in workflow to designer? I tried to type automation.jobinfo.jobinfo9 in default value column but i only “get automation.jobinfo.jobinfo9” in imageName field.
*The value i assigned in jobinfo9 in workflow is some imagename.
Thanks again and sorry that i am so green to planetpress.

Hi @ceci_cheung,

Just copy the value of the Job Info Variable 9 after you’ve executed the Run Script plugin on the Workflow side. The Default Value should be something like:

[ "image-1.png", "image-2.png", "image-3.png" ]

In addition, please remember that you will have to convert this value back to a JavaScript Array when you would like to use this value in your Connect Template. You can do that by making use of the JSON.parse() function in one of your Control, Standard or Post Pagination scripts, like for example:

var field = "";
var filenames = [];

field = automation.jobInfos.JobInfo9;

if (field !== "") {
	filenames = JSON.parse(field);
}

Hi @Marten

Do you mean that i need to copy the exactly value of JobInfo9 in Default value in designer like below??
But it is a variable data, the data is captured from a folder. Any other method to extract the value from jobinfo9 without put the exact value in default value? It’s because it will change if i use different data input.

That’s the correct Default Value.

There isn’t any other method than this one when you would like to test the result of making use of the Job Info Variable 9 on the Connect Designer side. Please note that this Default Value won’t be used by Workflow, as mentioned on our online documentation website:

Note that the default value is never actually used outside of the DataMapper. Its only purpose is to make it easier to design and test the data mapping configuration. […]

Source: ‘Properties and runtime parameters - PlanetPress Connect 2021.1 User Guide’

@Marten
I see. Please confirm whether i get it or not. The jobinfo9 i assigned in workflow cannot be extracted in designer when i am working on it. So i need to put a default value for development first.
But when i start the services and run in the workflow, the output will get the correct value(depends on what the folder listing captured) and put on the template?

Hi @ceci_cheung,

Yes, that’s correct. The value assigned to the Default Value input field of the Job Info Variable 9 within the Preprocessor Step Properties pane will only be used in the Connect Designer.

Thanks a lot! @Marten
And now i am trying to place the images in the template by script. However, i find that there is error “document is not defined” when i tried to change the image source by tag id like below:


May i know is it that i use the standard script incorrectly?