Monday, February 13, 2012

Dymo Printing

Need to connect your CRM installation to a custom label printer such as a Dymo printer? The following is another good example of customizing the CRM 2011 ribbon in order to the connect a Dymo printer in a context sensitive manner. We'll assume that we're integrating the Dymo printer to the CRM contact form. The end result is shown below whereby the address of the opened contact is sent to a Dymo label printer by simply clicking the "Dymo Print" icon.

So how can this be configured?

Start by using the Visual Ribbon Editor to configure the Dymo Print button on the ribbon (notice that I borrowed the icons for this from "Print Quote" icons but you could of course define your own web resource images and link to the those).

In the actions section, define a jscript function called DymoPrint and reference the jscript library where this function will live.

You can also define a DisplayRule so that the icon only shows in Existing forms (i.e. not the Create form). This makes sense as you should only be able to print once the form has been saved.

Add the jscript function to the jscript web resource indicated in the screenshot above which consists of 2 parts:

  1. Concatenate the print string
  2. Call the Dymo printer add-in

Note that in order for this to work the Dymo printer needs to be installed on the local computer. If this is not the case a friendly error message will be issued.

It also looks for the Label.lwl file which specifies the formatting for the print out in the 3 locations specified in the script. If you are using a different file name or this is in a different file path, you will need to update the script accordingly.

function DymoPrint() {

      var texttocopy = "";
      try {
                if (Xrm.Page.getAttribute("address1_line1").getValue() != null)                
                      texttocopy += "\n" + Xrm.Page.getAttribute("address1_line1").getValue();        
                if (Xrm.Page.getAttribute("address1_line2").getValue() != null)                
                      texttocopy += " " + Xrm.Page.getAttribute("address1_line2").getValue();           
                if (Xrm.Page.getAttribute("address1_line3").getValue() != null)                
                      texttocopy += " " + Xrm.Page.getAttribute("address1_line3").getValue();           
                if (Xrm.Page.getAttribute("address1_city").getValue() != null)                 
                      texttocopy += "\n" + Xrm.Page.getAttribute("address1_city").getValue() + ",";           
                if (Xrm.Page.getAttribute("address1_stateorprovince").getValue() != null)
                    texttocopy += " " + Xrm.Page.getAttribute("address1_stateorprovince").getText();           
                if (Xrm.Page.getAttribute("address1_postalcode").getValue() != null)                 
                      texttocopy += " " + Xrm.Page.getAttribute("address1_postalcode").getValue();         
                if (Xrm.Page.getAttribute("address1_country").getValue() != null)
                    texttocopy += "\n" + Xrm.Page.getAttribute("address1_country").getText();     

                var DymoAddIn, DymoLabel;
                DymoAddIn = new ActiveXObject("DYMO.DymoAddIn"); 
                DymoLabel = new ActiveXObject("DYMO.DymoLabels");
                if(DymoAddIn.Open("C:\\Documents and Settings\\All Users\\Documents\\DYMO Label\\Label Files\\LABEL.LWL"))   {           
                      DymoLabel.SetAddress(1, texttocopy);       
                      DymoAddIn.Print(1, true);
                }   else if (DymoAddIn.Open("C:\\Program Files\\DYMO Label\\Label Files\\LABEL.LWL"))   {      
                      DymoLabel.SetAddress(1, texttocopy);       
                      DymoAddIn.Print(1, true);
                }   else if (DymoAddIn.Open("C:\\Users\\Public\\Documents\\DYMO Label\\Label Files\\LABEL.LWL"))   {      
                      DymoLabel.SetAddress(1, texttocopy);       
                      DymoAddIn.Print(1, true); }  
                else   {           
                      alert("Error: Label file LABEL.LWL Not Found! Please speak to your system admin");
      } catch(e) {     
            alert("You do not have the Dymo AddIn installed. This is required for printing labels."); 



  1. Which DymoAddin is required to work with this?

    Ive made the changs but always get the error that I'm missing th Addin.

    I have the dymo software install and can print from that

  2. The script above 3 different paths in which the label file can be found. This path may vary depending on the version of Windows or the installation folder you selected. Also it might be that you do not have a label.lwl file in the specified location. You will need to ensure that the path to the label file is valid and then make sure to update the script above with the path to that location.

  3. Hi great post. Could you alter the label.lwl file to include a QR Barcode? Could the above function be modified to include the creation of the QR code linking to the unique URL of the record you want to print? This could then give you the option to scan the qr code and for it to then open the record.
    That would be a great function! Any help or advice on this would be appreciated!!

  4. Thanks Clayton. That looks like an interesting piece of functionality but those questions relate a little bit more to the ability to be able to configure the Dymo label rather than relating to CRM configuration. From a CRM configuration perspective we could put anything into the jscript logic. However jscript would be unable to alter files on the file server as that is a general limitation (feature) of jscript to prevent web pages behaving nefariously. So the question is really what Dymo is capable of. If you're able to feed it some data rather than point it to a file location then perhaps this is possible. However that's pretty much all I am able to say on the matter.

  5. Thanks Nahi for the feedback, I am building an Asset Management Tracking/Maintenance Scheduling system in our CRM instance, and I thought it would be quite cool if we could print labels for all our equipment which we would be able to scan and bring up the CRM record. If I get any further with it I'll let ya know. Thanks!

  6. Note sure if this link is helpful in the javascript behind QR Codes for Dymo?

    Thanks Clayton

  7. Thanks for the link. I haven't studied it in detail but my guess is that it should be doable. Here's how I think it should work:

    1. Create the Dymo label for the barcode including the barcode type you wish to encode it in.

    2. Concatenate the text you wish to send to Dymo as in the example above

    3. Open the Dymo label and print the text as in the example above

    I have to believe that the logic for encoding from text to barcode format is contained within the Dymo code itself. So all you should need to pass is the text along with the Dymo label that will specify to Dymo to print it out in a barcode format and Dymo should take care of the rest.

    That's how I would expect it to work. How it actually does work - I cannot say for sure but hopefully you'll be letting us know after you get it to work.

  8. Nice writeup, does this actually create the activex object or is there something that needs installed to IE when using dynamicsCRM through the browser? I am using this in IE9 and Dymo software 7.8.08 on a windows 7 box.

    I edited it so that it can find my LWL file but it doesnt do anything when I click on the button. Before I pointed it to my LWL file it was showing me the "you do not have the addin installed" message so I know it is firing off the function call. I know with GoldMine we had to install an addin specifically for Goldmine but I couldnt find anything for IE.

  9. The only thing you need installed on the workstation is the Dymo Addin. As far as I know there is no requirement for any browser plugin.

  10. Thanks for the input, I got this worked out. It helps when you display a message box containing the exception. :D
    I ended up with the button on the Homepage and not the contact form so the values were not being populated from the object. I put it on the Form itself and I was able to get some things to come across.

    I haven't found a way to print multiple contacts with one click from the main contacts homepage, I'm not sure how to see what all is marked as checked in the list.

  11. Excellent.

    Doing it from the main contact home page may be tricky. Because you don't have access to the form fields as you do when running this from within the contact form. You may be able to design some REST or SOAP calls in order to retrieve the form fields - I haven't tried it so not sure if there any gotchas.

    As for retrieving the checked items - can't remember off hand how to do this either. You may want to check the SDK for some code samples.

    Either way, it's an interesting to challenge to be facing. Hope you manage to figure it out and will be happy to know if you did and what approach you ended up taking. Good luck!