Replace low res QR code

Post Reply
nna
Member
Posts: 30
Joined: Tue Jul 21, 2020 9:57 am

Replace low res QR code

Post by nna »

Hi all

I'm trying to create a small Switch flow with PitStop Server where I can put in a PDF with a low resolution QR code and replace that with one created by PitStop Server. I've managed to read the QR code and am able to pass it to Switch through the report. I then save the contents of the QR code into a private data field and then create the new QR code in a separate action list. The problem: The content is multi-line (a VCARD) and apparently neither PitStop nor Switch's private data support multi-line text in that scenario. Is there another way I could approach this?
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: Replace low res QR code

Post by freddyp »

Switch private data does support multi-line text. Where do you get the value of the private data from? Specifying it with "Set job private data" on a folder will indeed not work, because there each line is considered to be the definition of a single piece of private data.

These two scripts work as expected and illustrate that private data can be multi-line:

Code: Select all

async function jobArrived(s: Switch, flowElement: FlowElement, job: Job) {
  let crlf = String.fromCharCode(13) + String.fromCharCode(10);
  await job.setPrivateData("QR", "a" + crlf + "b" + crlf + "c");
  await job.sendToSingle();
}

Code: Select all

import * as fs from "fs";

async function jobArrived(s: Switch, flowElement: FlowElement, job: Job) {
  await job.setPrivateData("QR", fs.readFileSync("/Users/fp/Desktop/abc.txt").toString()); //abc.txt contains abc on three separate lines
  await job.sendToSingle();
}
And then of course the QR code is placed with a variable that points to the private data key QR.

In a VCARD file new lines are defined with \n. In other words, to get them onto a multi-line in a QR code you will have to replace the \n by a real crlf, the definition of which you can find in the first script.
nna
Member
Posts: 30
Joined: Tue Jul 21, 2020 9:57 am

Re: Replace low res QR code

Post by nna »

Your question put me on the right track, Freddy! I get the value from a PitStop report that is attached as a dataset in Switch. Meaning, I can skip the whole Private data business and just directly add the QR VCARD value to a variable set.
Post Reply