OL Learn

Barcode position


#1

Need to place 10 barcodes on a page.
The barcode position are random.
The barcode values and X-Postion + Y Postion are delivered by the datamapper
I have placed 10 barcodes on the page, with the values from datamapper Barcode1 - Barcode10

I have added a script which control the Barcode.

The script can turn the Barcode on an off - if it is not present.

I have also tried to move the barcode position with the script, but it is not working.
Can anyone see what I’m doing wrong in the script.
Barcode1_X_Value holds the X position in the datamapper in mm x 100
Barcode1_X_Value holds the Y position in the datamapper in mm x 100
I have tried to replace XPos+YPos in the script with just values - same result barcode is not moving around.

Script:
if (record.fields.Barcode1 == “”) {
results.attr(“data-conditional”, “”);
results.hide();
}
else
{
results.css(“postion”,“absolute”);
var XPos = record.fields.Barcode1_X_Value / 100;
var YPos = record.fields.Barcode1_Y_Value / 100;
results.css(“top”, XPos + ‘mm’);
results.css(“left”,YPos + ‘mm’);
results.attr(“offset-x”,0 + ‘mm’);
results.attr(“offset-y”,0 + ‘mm’);
results.show();
}


#2

Hi,

Why are you dividing by 100? I’m going to test this now. I thought it would/was working but it is not.

Regards,
S

EDIT: Silly question - You are placing the barcode ID as the selector in your script?


#3

I’m deviding by 100 cause the values returned by datamapper could be 13270 = 132,7mm

What do you mean by barcode ID in the script. I test if Barcode1 is blank=do not have a value. If it is blank I’m hiding it.

I’m not a script expert, doing my best :slight_smile:


#4

Don’t worry. I had to learn javascript coming from PP7 to Connect. I don’t claim to be an expert. I have not done positioning like this in a while and the answer was staring me in the face.

results.css('position', 'relative');

And you have your x/y backwards :slight_smile:

EDIT: My final script. I added data to the template using counters. File-Add data-Generate Counters. I added a code 39 barcode to my template. It has an ID with value barcode. I opened the barcode script that Connect adds to the scripts pane and selected Expand to edit the code within the script.

var field, result = "";

if (record.fields.Counter == "") {
	results.attr("data-conditional", "");
	results.hide();
}else{
	field = record.fields["Counter"];
	result += field;
	results.text(result);

	results.css("position", "relative");
	var XPos = 3000 / 100;
	var YPos = 5000 / 100;
	results.css("top", YPos + 'mm').css("left",XPos + 'mm');
	results.show();
}

#5

Thanks it is almost working.
But how do I control each barcode position with the script ?
Thought that when put in Top, Left in the script it took the x,y from the top of the page 0mm,0mm
But it is not, I can see that if i change the height of one barcode it changes the position of the rest of the barcodes. So it looks lige each barcode is controlling the next one. It should not do that.

Ended up with this script:
var field, result, OffsetX, OffsetY, BarcodeHeight = “”;

if (record.fields.Barcode1 == “”) {
results.attr(“data-conditional”, “”);
results.hide();
}else{

field = '*' + record.fields["Barcode1"] + '*';
result = field;
results.text(result);
OffsetLeft = 4;
OffsetTop = 0;
BarcodeHeight = 10;
results.css("position", "relative");
var TopPos = (record.fields["Barcode1_Y_Value"]/ 100) + OffsetTop; 
var LeftPos =(record.fields["Barcode1_X_Value"]/ 100) + OffsetLeft;
results.css("top", TopPos + 'mm').css("left",LeftPos + 'mm').css("height", BarcodeHeight + 'mm');
results.show();
}


#6

Used:
results.css(“position”, “fixed”);
And the position was locked/fixed.
Template working now……


#7

If you want to control all 10 barcodes you need 10 scripts. I don’t know of a way to have one script to control all barcodes. That is why I mentioned the barcode ID matching the scripts selector. (They are married) So in my mind you could have gone two ways. 1. Created 10 scripts that only control the barcodes x/y etc. (that is 10 barcode scripts added by Connect and 10 scripts you manually added to the scripts pane and entered each barcodes matching ID in the selector box e.g. #barcode) or 2. You Expanded all 10 barcode scripts and modified their codes. Judging by your script above it looks like the latter.

I don’t think it is possible to only have one script. I could be wrong but only OL will be able to advise that.

EDIT: I see you have it working before I replied. Did you use multiple scripts or one? Just curious :slight_smile:


#8

I used 10 scripts for 10 barcodes - just copy/past


#9

That is what I thought. Glad you got it sorted.