Create and move file

Post Reply
MY001
Newbie
Posts: 9
Joined: Mon Feb 15, 2021 9:47 pm

Create and move file

Post by MY001 »

Hi everyone

I am creating a code that generates image from HTML code. I am using puppeteer library which server this purpose (converting html template into an image).

My goal is having a job arrives to a script element point to trigger the script to generate the image.

The issue I am encountering is that the script requires to set the path where you want to save the generated image.

Any idea how can I set the script to generate the image and "SendToSingle()" be the path where the image is created, so that image continues the journey through the flow.

This is the script I am using

Code: Select all

async function jobArrived(s,flowElement,job){

const puppeteer = require('puppeteer')
const htmlString = `<html>
<body>
<head>
     <p>HTML CODE</p>
    </body>
</html>`;

(async () => {
  const browser = await puppeteer.launch()
  const page = await browser.newPage()
  await page.setContent(htmlString)
  await page.screenshot({path: THIS IS WHERE THE SCRIPT WANTS ME TO PUT THE PATH WHERE TO SAVE THE GENERATED IMAGE})
  await browser.close()
})()

}
It is preferrably if there is way that the new generated image to carry same data of the job arrived to the entry point. However, if that's not possible that's ok, it can be redirected to a recycle point and the new image continues the journey without carrying the previous data.

PS: I tried to set the path to be the next folder in the flow and it does happen, but Switch still show 0 files in that folder until I deactivate/reactive the flow then it becomes visible.

Thank you in advance.
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: Create and move file

Post by freddyp »

You are missing some insights in the fundamentals of Switch scripting and especially the part about how to create temporary files and send those to the outgoing connection. Have a look at https://github.com/EnfocusSW/HotFolderMonitor. At the end of that sample script you will see how to do that. And of course also in the documentation.

As a reminder for everybody, here is what Laurent posted a couple of weeks ago: viewtopic.php?f=26&t=4105
Post Reply