Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: QR Codes  (Read 13010 times)
Paul M.
Posts: 30


« on: September 18, 2020, 04:25:56 pm »

Hi,

Has anyone used QR codes on a report?
I am looking to put some data from a 4gl variable in the QR code and the page number.

I can put the 4gl data in using Code Value property and the page number using Code Value Expression property(overrides the codeValue property) but only the page number appears.
Is it possible to combine both?

Using fglrun 3.20.10 rev-1ee2d468

Thanks.
Alex G.
Four Js
Posts: 148


« Reply #1 on: September 21, 2020, 09:24:12 am »

Hi,

I just verified (please correct me if I misunderstood the question). You can either specify an RTL expression for the "Code Value" property that uses any 4GL variable and RTL function or specify a PXML expression for the "Code Value Expression" property that uses any combination of literal values, the concatenation operator '+' and PXML functions like format() and getPhysicalPageNumber().
In other words, you can write codeValue="This is page 5 of the report "+orderline.orders.report_name" and codeValueExpression="This is page "+format(getPhysicalPageNumber(),ARABIC)+" of the report 'SalesReport'" but you cannot write codeValueExpression="This is page "+format(getPhysicalPageNumber(),ARABIC)+" of the report '{orderline.orders.report_name}'".
There is no technical reason why that shouldn't be possible so that it could be allowed in a future version but the current implementation doesn't support it.

Best regards,

Alex
Alex G.
Four Js
Posts: 148


« Reply #2 on: September 21, 2020, 09:53:45 am »

Sorry, my first answer was too quick.
I just rechecked and this expression worked just fine: codeValueExpression="{orderline.orders.billfirstname.trim()}"+format(getPhysicalPageNumber(),ARABIC)
In an OrderReport report it yields a code that scans as "Fred1" on the first page.
So contrary to what I said before, you can have an expression that contains both 4GL variables and PXML page number functions.
I am curious to know what this is used for. Would you be willing to explain the business need and give an example of the type of text that is encoded?

Regards,

Alex
Paul M.
Posts: 30


« Reply #3 on: September 21, 2020, 12:25:53 pm »

Hi Alex,

Thanks for taking the time to look at this.

I have tried the codeValueExpression and get the error attached.

What we want to do is the following:

- User prints delivery dockets
- Dockets given to delivery driver
- On delivery customer signs docket
- Driver returns docket to office
- Office scans the signed dockets
- Associate scanned images to transactions on database for future viewing.

I would like to put a small json string in a qr code that a small python script can then read from the scanned image  giving enough information to associate to a specific transaction in the database.

We have got this to work but we would also like to include the page number in the qr code so that the scanned images could be shown in the correct order. In an ideal world we would also love to include the total number of pages per delivery docket so that the system knows that there are no missing pages but I guess that may not be possible as that is only known at the end of the print.

Text being encoded :  {"doc_type":"BTL","depot_code":"E01","trans_no":494}

Is the {} in the json string causing the error?






* QR_003 (Small).png (77.26 KB, 480x511 - viewed 2199 times.)

* QR_004.png (42.76 KB, 1014x483 - viewed 2193 times.)
Alex G.
Four Js
Posts: 148


« Reply #4 on: September 21, 2020, 03:23:56 pm »

Hi Paul,

the parse error is caused by the double quotes in the JSON value (not the curly braces).

The parsing works as follows: A PXML-RTL expression is evaluated firstly by the RTL evaluator by searching the PXML-RTL expression for substrings of the pattern {expr} and replacing these by their evaluation result. The result of this substitution is then evaluated in a second pass by the PXML evaluator.
Examples:

Example 1 (a numeric property):
PXML-RTL-expression: 1+{2+3}*4+{5*6}+9
Expression after RTL evaluation: 1+5*4+30+9
Expression after PXML evaluation: 60

Example 2 (a string property, the variable aVariable is set to "foo"):
PXML-RTL-expression: "{aVariable}"+" "+format(4,ARABIC)
Expression after RTL evaluation: "foo"+" "+format(4,ARABIC)
Expression after PXML evaluation: "foo 4"

Example 3 (a string property, the variable aVariable is set to ""foo""):
PXML-RTL-expression: "{aVariable}"+" "+format(4,ARABIC)
Expression after RTL evaluation: ""foo""+" "+format(4,ARABIC)
Expression after PXML evaluation: ERROR because ""f is not a valid start of a PXML-expression

Example 4 (a string property, the variable aVariable is set to "\042foo\042" (\042 is the octal escape for a double quote)):
PXML-RTL-expression: "{aVariable}"+" "+format(4,ARABIC)
Expression after RTL evaluation: "\042foo\042"+" "+format(4,ARABIC)
Expression after PXML evaluation: ""foo" 4"

Example 5 (a string property, the variable aVariable is set to ""foo""):
PXML-RTL-expression: "{aVariable.replaceAll(34.toChar(),"\\042")}"+" "+format(4,ARABIC)
Expression after RTL evaluation: "\042foo\042"+" "+format(4,ARABIC)
Expression after PXML evaluation: ""foo" 4"

So the fix for your problem is to replace any double quotes in the variable by an octal escape.
This you can do by using the RTL replaceAll() method so that your expression would look as follows: "{pr_header.qr_code.replaceAll(34.toChar),"\\042")}"+format(getTotalNumberOfPhysicalPages(),ARABIC)

Your worries regarding the usage of a PXML total page number function like getTotalNumberOfPhysicalPages() are unfounded.
Issues like the need to delay printing until the total number of pages is known, is taken care of. Likewise the bar code images are updated in the preview window as soon as the total number of pages is known.

I am asking myself however if doing it this way isn't overcomplicating things a little.
The mechanism, for what we call the "Page n of m" problem in conjunction with bar codes, is designed to drive an enveloping machine so handle a batch print of documents with variable page length.

If I understand you correctly, then you are not actually interested in actual page numbers but you "just" need a number to bring images into an order.
If this is the case, why don't you simply define a variable in the report that is incremented with each print of the variable pr_header.qr_code like this:

LET aCounter=aCounter+1
PRINT pr_header.*, aCounter
 
.. and then use the literal code value property with this expression like this: codeValue="{{pr_header.qr_code+";"+aCounter}}"

Then things are straightforward you also don't need to quote the JSON.
 
Paul M.
Posts: 30


« Reply #5 on: September 21, 2020, 04:11:12 pm »

Hi Alex,

Thanks for the lesson on PXML, I didnt know any of that . There should be a tutorial section on the web site with this kind of information explained( or have I not looked hard enough :-) )

I guess I am using the json to keep things simple when I read the data back in from the scanned image. It might be easier to send it out as a delimited string.

I get what you are saying by using aCounter as I can increment every time I do an output to report and use that to order the scanned pages. I am printing the record pr_header  just once in the FIRST PAGE HEADER section and also creating the QR code in the same section in the design then using x and y to position at the top of each page. I didnt think I could access any variables outside the first page header section.



Thanks.
Reuben B.
Four Js
Posts: 1046


« Reply #6 on: September 25, 2020, 08:52:09 am »

...

Thanks for the lesson on PXML, I didnt know any of that . There should be a tutorial section on the web site with this kind of information explained( or have I not looked hard enough :-) )

...


there is probably material for an Ask-Reuben article https://4js.com/ask-reuben/ on the difference between RTL and PXML.  The team are going to review the documentation.   

I think the key thing to be aware of is that there are two similar languages used for property values, RTL and PXML http://4js.com/online_documentation/fjs-gst-manual-html/#gst-topics/c_grd_rtlexpressions_001.html.  When you click on the fx button, two different dialogs appear depending if it is RTL or PXML.  With Barcodes, Code Value is a String, uses RTL and so is evaluated when the data is read into the report engine.  Code Value Expression is a PXML String, uses PXML and so is evaluated when the page is laid out (hence its ability to include page numbers).  Within PXML you can embed RTL with the {} notation http://4js.com/online_documentation/fjs-gst-manual-html/#gst-topics/c_grd_rtlexpressions_006.html.

So I think key points here are to recognise that ...

Code Value Expression is PXML type and so you'd use PXML to create an expression using the Page Number methods.  These are not available in an RTL expression.
You can embed an RTL expression inside a PXML expression, so whilst typical usage for this might be an X-size value, the same technique can be used for other PXML values such as Code Value Expression
The need to replace quotes in the data with the octal escape.

Reuben




Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines