Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Dymo labels javascript (API) issue

Bas de KlerkDec 17 2012 — edited Dec 18 2012
Hi all.

APEX 4.2
11gR2 XE database.


I'm trying to print labels directly from APEX via a JS library from DYMO (DYMO label framework for javascript).
I would like to fetch the XML for the label layout dynamically from the database instead of fixed assigning this in JS, that way I can store all the templates for labels in the database and fetch the appropriate one for the task I'm doing ).
If I use the fixed code it works fine, code looks like this ( label XML layout is assigned to labelxml variable in the first few lines ) :
function printadres(labeltext )
{
    try
	{ 
var labelxml = '<?xml version="1.0" encoding="utf-8"?>\
    <DieCutLabel Version="8.0" Units="twips">\
        <PaperOrientation>Landscape</PaperOrientation>\
        <Id>Address</Id>\
        <PaperName>30252 Address</PaperName>\
        <DrawCommands/>\
        <ObjectInfo>\
            <TextObject>\
                <Name>Text</Name>\
                <ForeColor Alpha="255" Red="0" Green="0" Blue="0" />\
                <BackColor Alpha="0" Red="255" Green="255" Blue="255" />\
                <LinkedObjectName></LinkedObjectName>\
                <Rotation>Rotation0</Rotation>\
                <IsMirrored>False</IsMirrored>\
                <IsVariable>True</IsVariable>\
                <HorizontalAlignment>Left</HorizontalAlignment>\
                <VerticalAlignment>Middle</VerticalAlignment>\
                <TextFitMode>ShrinkToFit</TextFitMode>\
                <UseFullFontHeight>True</UseFullFontHeight>\
                <Verticalized>False</Verticalized>\
                <StyledText/>\
            </TextObject>\
            <Bounds X="332" Y="150" Width="4455" Height="1260" />\
        </ObjectInfo>\
    </DieCutLabel>';

		var label = dymo.label.framework.openLabelXml(labelxml);

		// set label text
		label.setObjectText("Text", labeltext);
					
		// select printer to print on
		// for simplicity sake just use the first LabelWriter printer
		var printers = dymo.label.framework.getPrinters();
		if (printers.length == 0)
			throw "No DYMO printers are installed. Install DYMO printers.";

		var printerName = "";
		for (var i = 0; i < printers.length; ++i)
		{
			var printer = printers;
if (printer.printerType == "LabelWriterPrinter")
{
printerName = printer.name;
break;
}
}

if (printerName == "")
throw "No LabelWriter printers found. Install LabelWriter printer";

// finally print the label
label.print(printerName);
}
catch(e)
{
alert(e.message || e);
}
};
but when I try to fetch the same XML from a text field on my form it fails with a "getObjectByNameElement(): no object with name 'Text' was found" error which is a custom error from the DYMO library.
I'm unable to find the big difference in the 2 approaches. If I test the variable labelxml by putting it in an alert the value seems fine ( it contains the XML string which is in P11_LABELTEMPLATE which is exactly the same as the static assigned text in the previous example ).
The code then looks like this :
function printadres(labeltext )
{
try
{
var labelxml = $v('P11_LABELTEMPLATE'); // This is the dynamic assigment which somehow fails

var label = dymo.label.framework.openLabelXml(labelxml);

// set label text
label.setObjectText("Text", labeltext);

// select printer to print on
// for simplicity sake just use the first LabelWriter printer
var printers = dymo.label.framework.getPrinters();
if (printers.length == 0)
throw "No DYMO printers are installed. Install DYMO printers.";

var printerName = "";
for (var i = 0; i < printers.length; ++i)
{
var printer = printers[i];
if (printer.printerType == "LabelWriterPrinter")
{
printerName = printer.name;
break;
}
}

if (printerName == "")
throw "No LabelWriter printers found. Install LabelWriter printer";

// finally print the label
label.print(printerName);
}
catch(e)
{
alert(e.message || e);
}
};
I'm not sure if this is an APEX or JS question/problem but I hope someone can point me in the right direction.

Regards
  Bas                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
This post has been answered by Bas de Klerk on Dec 18 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 15 2013
Added on Dec 17 2012
2 comments
3,482 views