Jump to content

Using custom phone labels from a field in a QR code


Recommended Posts

I'm trying to allow the user to select the label for a phone number they want to appear in a QR code using a field, however I'm having trouble getting the QR code to use the contents of the field. The entire rule I'm using is below for reference, however the line I'm trying to figure out is :



"TEL;type=Toll Free": Field("TollFree"),



This seems to work fine and displays the label as Toll Free, then the number correctly. However I'm trying to change it to something like this:





"TEL;type=' + Field('C1Label') + '": Field("TollFree"),


With that it is displaying the literal string ' + Field('C1Label') + '



I'm guessing it has to do with using different single / double quotes to delineate what should be interpreted as JavaScript vs displayed as literal text but I can't quite figure it out.



Any help would be appreciated!



-Jake Merrick








Entire rule:

//Function to Make a QR code without truncating font size


function MakeQRBarcodePreciseSize(DataToEncode, ProcessTilde, EncodingMode, ErrorCorrection, PreferredFormat, PointSize, NoFontTag, Font)


var encoded = EncodeQRBarcode(DataToEncode, ProcessTilde, EncodingMode, ErrorCorrection, PreferredFormat, PointSize, NoFontTag, Font);


var ReplacedBR = ReplaceSubstring(encoded, "\r\n", "<br>");

var ReplacedSpaces = ReplaceSubstring(ReplacedBR, " ", "");


if (isNaN(PointSize))

return ReplacedSpaces;


var WithPointSize = "<z newsize=\"" + Number(PointSize) + "\">" + ReplacedSpaces;

if (NoFontTag)

return WithPointSize;


var WithFontTag = "<f name=\"" + Font + "\">" + WithPointSize;


return WithFontTag;



// vCard 3.0 format

// http://en.wikipedia.org/wiki/vCard


var info = {

N: ToTitleCase(Field("LastName")) + ';' + ToTitleCase(Field("FirstName")) + ';;;;',

FN: ToTitleCase(Field("FirstName")) + ' ' + ToTitleCase(Field("LastName")),

TITLE: ToTitleCase(Field("Title1")),

"TEL;type=Phone": Field("Phone"),

"TEL;type=Toll Free": Field("TollFree"),

EMAIL: ToLower(Field("Email")),

URL: "innovativeos.com",



var result = ["BEGIN:VCARD", "VERSION:3.0"];

for (var label in info)


if (info[label])

result.push(label + ":" + info[label]);




var EncodingMode = "Byte";

var ErrorCorrectionMode = "M";

var PreferredFormat = "0";


var PointSize = "3.4";

var NoFontTag = false;

var Font = "IDAutomation2D";

var ProcessTilde = false;



function CopyfitLineWithMagnifyTag(line, widthInPoints, AllowToExpand)


var tm = new FusionProTextMeasure;


if (tm.messages)

ReportError("CopyfitMagnifyLine: " + tm.messages);


if (tm.textWidth < widthInPoints*100 && !AllowToExpand)

return line;


var factor = Round(widthInPoints / tm.textWidth * 10000, 0) - 1;

return "<magnify type=pointsize factor=" + factor + ">" + line + "</magnify>"; //this horizontally scales type, to proportional scale type change "type=setwidth" to "type=pointsize"


var textFrameWidth = FindTextFrame("QRBox").GetSettableTextWidth() / 100; //change "ContactBox" to the name of the text frame


return CopyfitLineWithMagnifyTag(

'<p br=false linespacing=".833333">' + MakeQRBarcodePreciseSize(result.join(Chr(13) + Chr(10)), ProcessTilde,EncodingMode, ErrorCorrectionMode, PreferredFormat,PointSize, NoFontTag, Font), textFrameWidth);

Link to comment
Share on other sites

You can't "compute" a property name in a literal object initializer like that. You have to set that property separately, with its own declaration. I can't test this without your data file, but I think you want to do this, AFTER the closing bracket } for the initializer of the "info" object (right before the line starting with "var result"):

info["TEL;type=" + Field("C1Label")] = Field("TollFree");

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...