Google Chart API - QR Code

19,899 views
Skip to first unread message

Buffelsdrift Mountain Bike Park

unread,
Feb 1, 2017, 1:18:04 PM2/1/17
to mementodatabase
Note I am not a programmer but a MountainBiker trying to build my own App.

Two questions:
1. What would the Memento field/solution be to house the code below to display a QR Code INLINE in the record in View or Edit Mode?
~ Javascript field
~ Hyperlink field
~ Trigger populating an Image field
~ Trigger populating a RTF field

A Hyperlink field renders the QRCode in a browser window - like the Rel 4.2.0 does by popping up in a seperate window. However I want it to display in the record (like an image) so that I can send it to my Customer.

One can generate a QR code by sending input parameters to this Google Chart API url https://chart.googleapis.com/chart.
There are three mandatory Parameters that needs to be send as an input.
Cht – It is used to determine the type of Google Chart API. We need to set this as ‘qr’ to generate QR codes.
Chs – Output QR Image Size in Pixels <width>x<height> ( i.e., 150×150)
Chl – This should be the data to be encoded.
Sample Data:
https://chart.googleapis.com/chart?cht=qr&choe=UTF-8&chs=150×150&chl= http%3A//www.luckydroid.com/

function generateQRCode(){
this.qrImage.style.display ='none';
Var myQRValue = entry().field('myFieldtoUse');
this.qrImage.src=" http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=
+myQRValue;
this.qrImage.style.display ='inline';
}

2. If the answer is a Trigger that populates a Image or RTF field or Javascript field, then what is the correct Javascript code above?

Bill Crews

unread,
Feb 1, 2017, 1:43:07 PM2/1/17
to mementodatabase
This is way beyond me. Don't anyone wait for me to answer it. Maybe Eugene? Anyone else?

Eugene Kartoyev

unread,
Feb 1, 2017, 8:47:14 PM2/1/17
to mementodatabase
Hey, Bill! I'm all into my app, now.... but I'll give the holy javascripture a try ;) 

<h1> Some text </h1> - makes a heading.
<br> - breaks line
<img src="http..." width="XX%" /> - make an image from source src

So, we need to construct the rtf field content.



For that, we need to set up a data field and a rich text format (rtf) field.

Then write a trigger (at opening, before display):

// function to replace some characters in a string

function replaceAll(str, find, replace) {
  return str.replace(new RegExp(find, 'g'), replace); 
}

// get data to transmit

var a=entry().field("data");

// replace all "non-url" symbols, e.g. space=%20

a=replaceAll(a," ","%20");  // do the same thing for other non-url symbols you will use

// form the rtf field contents. Use html

var toSet= "<h1>QR Code</h1>  <img width=\"70%\" src=\"http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl="+a+"\" />";

message(toSet);

// set the field content

entry().set("rtf",toSet);


You should be careful with the data field, because many non-letter symbols have to be written in %XX format. For example, space is %20, + is %3B etc.

I guess, you could use the string function to replace such symbols if they are planned to use. 

Please, test if it provides correct QR.
Screenshot_2017-02-02-04-15-23.png

Buffelsdrift Mountain Bike Park

unread,
Feb 1, 2017, 11:57:33 PM2/1/17
to mementodatabase
Hi Eugene.

Thank you for taking the time to try and come up with a solution. Appreciate all the effort guys like you and Bill put into assisting non developers like me.

If this works then I will add you to my Memento Coding Hero list - Sorry Bill is the first one in the list - LOL

I will try and let you guys know

BTW my name is Henry

Bill Crews

unread,
Feb 2, 2017, 12:56:51 AM2/2/17
to mementodatabase
Careful, Henry! It's best not to play favorites around here. We each have our unique superpowers. 8-D

Buffelsdrift Mountain Bike Park

unread,
Feb 8, 2017, 3:46:01 AM2/8/17
to mementodatabase
Eugene, Bill it is working like a charm.
Exactly what I was looking for!
I now have an "Inline" QRCode in the customer record and not a popup as natively built by Vasya the developer, which by the way is cool in itself to have that natively in a system by a click of a button

Atma Tanjung

unread,
Oct 1, 2018, 4:15:36 AM10/1/18
to mementodatabase
Hi,

My data is contains text and simbol (#), but why the QR code can't be scanned, what's the problem, please help me.


Thank you
Reply all
Reply to author
Forward
0 new messages