Dynamic Images Based On Data File Name Not Working

Hi,

I have a template that uses three images. These images need to change based on the filename containing a certain keyword. I created a preprocessor field/extract step that is set to automation.variables.dataName. I then created the following script.

var data;

data = record.fields[“dataName”];

if (data.includes(“Current”)){
results.attr(“src”, “images/Flysheet_INTERNAIONAL_CURRENT.pdf”);
} else if (data.includes(“Last Copy”)){
results.attr(“src”, “images/Flysheet_INTERNATIONAL_last issue”);
} else if (data.includes(“2 to go”)){
results.attr(“src”, “images/Flysheet_INTERNAIONAL_2_to_go.pdf”);
}

The script has a selector called #dynamicImage. I dragged a image to the templates print context section 1 and added dynamicImage to its ID in the attributes pane. If I change the default value of field to Current, then in the designer the image changes to the Current image when previewing.

However from workflow it does not change the image, it instead uses the first image that I added to the template. I did add a local variable in workflow called dataName and set its value from a jobinfos in a script like this.

var dataFileName = Watch.GetJobInfo(9);

Watch.SetVariable(“dataName”, dataFileName);

The jobinfo 9 above is populated with %O.

I’m not sure what is wrong here, you advice will be appreciated.

Regards,

S

Have you checked if the value in the dataName field is the expected one? You should print it out on your template to make sure it is.

If it isn’t, you could modify your data mapping config so it uses automation.jobinfos.jobinfo9 instead of the dataName variable. This will tell you if the issue is related to the passing of the variable itself from Workflow to the DataMapper. Remember that when passing a Workflow variable to the DM, you have to declare that variable in the DM as well, using the exact same name as in the Workflow.

Let’s start with the above checks, then let us know if it helped you move forward in determining the cause of the issue.

Hi Phil,

The automation.jobInfo.JobInfo9; is what I tried first and now it is working. Odd that the variable did not since I pass values to my templates that way always.

Thanks for the assist.

Regards,

S