Dynamic background in template from automation

Hello.

I try to use dynamic background form JobInfos variables workflow to template.

For testing I use constant string since the JobInfos does’nt exist during design.

When I run the template from the workflow, the Jobinfo stay empty…

var result = “”;
result = automation.jobInfos.JobInfo2;
if (result == “”)
result = “C:\Temp\job0109OO563G20DC333AE5FB5.dat.pdf”;
result = “file:///” + result.replace(/\/g,“/”);
var background = merge.template.contexts.PRINT.sections[“Section 1”].background;
background.source = BackgroundResource.RESOURCE_IMAGE;
background.allPages = true;
background.url = result;

Are you outputting a web page?
Automation.jobInfos.JobInfo2 will only work in a Web context or in your Datamapper.

Now if you want to use it in a Print context, then you can get the value from your Datamapper and then store it into a field of your datamodel. Better yet, pass it as a runtime parameter.

Hope that helps.

Hi hamelj,

Why better yet? Is runtime use better than jobinfo?

Regards,
S

Like I previously mentioned:

Automation.jobInfos.JobInfo2 will only work in a Web context or in your Datamapper .

So, in case of Print context you need to set up the automation.jobInfos.jobInfo2 from the Datamapper to a field in the datamodel in order to have access to it from the Template.

Runtime parameters are accessible directly from the Template, which, to me, is better!!! :stuck_out_tongue_closed_eyes:

Ok, I create a create print action in my worflow and pass the fulname of my background PDF by parameter.

Template ignore it…
Or I don’t know where the action put the PDF result…

var result = “”;
result = merge.template.parameters.pdfDocument;
if (result == “”)
result = “C:\Temp\job0109OO563G20DC333AE5FB5.dat.pdf”;
result = “file:///” + result.replace(/\/g,“/”);
var background = merge.template.contexts.PRINT.sections[“Section 1”].background;
background.source = BackgroundResource.RESOURCE_IMAGE;
background.allPages = true;
background.url = result;

2021-07-15%2014_13_28-Window

2021-07-15%2014_17_33-Window

try with this instead:
result.replace(/\\/g,“/”);

You need to escape your backslash as it is a reserved character in Regex

To explain all process :

  1. Capture PDF file into a directory.
  2. Read barcode into the PDF by barcode reader action
  3. Process datamapper have SQL source with parameter contains the bar code
    All above work fine.
  4. I want to create print content overlap the current PDF file (give the orinal pdf from pdf as background and put informations from SQL database on it.
  5. Then create a PDF document result of merging.

Thanks for your help

My backslash is escape by a backslash this copy paste into forum transform it.

I found where is my error …
It’s a basic mistake, I don’t create task and output before create print content…

Excuse me for the time.

HH

No problem…that is the reason for this forum and very often we find our own solution, we just need to explain it to someone else and we see our mistakes…I know I do!

Happy day :slight_smile:

2021-07-15%2017_49_16-Window

Thanks a lot.