Skip to end of metadata
Go to start of metadata

Description

This article presents a script to print a specific image based on the input value of a label field. The concepts presented here can be applied to any requirement for logically selecting a label image.

The following example shows how to print a selected certification image based upon the value of input field named country.

How to print a specific image using label scripting

  1. Create a new label.
  2. Set up an input field and set the field name to country.
  3. Add an image field named cert_image.
  4. Set the Data Source of the image field to Keyboard (instead of the default Fixed Image setting).
  5. Add a scripting field on the label.
  6. Fill in the scripting field data source window with the following contents:

     

    Sample Image Selection Script

    Icon
    //define variable
    var input = (label.fields.field.( @ name == 'country'). @ data);
    //define if statement to select correct image
    if (input == "USA") {
        label.fields.field.( @ name == 'cert_image'). @ data = "ETL300.PCX";
    } else if (input == "France") {
        label.fields.field.( @ name == 'cert_image'). @ data = "CE.PCX";
    } else if (input == "Spain") {
        label.fields.field.( @ name == 'cert_image'). @ data = "CE.PCX";
    } else if (input == "Canada") {
        label.fields.field.( @ name == 'cert_image'). @ data = "CSA300.PCX";
    } else {
        label.fields.field.( @ name == 'cert_image'). @ data = "";
    }
  7. Make sure that the images used in the script are saved in the Loftware Images location as defined in Design32 > Options > File Locations.

  8. Test the label output using various input values for the country field.

    Sample Image Selection Script

    Icon
    //define variable
    var input = (label.fields.field.( @ name == 'country'). @ data);
    //define if statement to select correct image
    if (input == "USA") {
        label.fields.field.( @ name == 'cert_image'). @ data = "ETL300.PCX";
    } else if (input == "France") {
        label.fields.field.( @ name == 'cert_image'). @ data = "CE.PCX";
    } else if (input == "Spain") {
        label.fields.field.( @ name == 'cert_image'). @ data = "CE.PCX";
    } else if (input == "Canada") {
        label.fields.field.( @ name == 'cert_image'). @ data = "CSA300.PCX";
    } else {
        label.fields.field.( @ name == 'cert_image'). @ data = "";
    }
Icon
Refer to the attached label that contains this solution: Article-2016013.lwl

Article Number

2016013

Versions

 LPS 9.5.2 and higher

Environment

Any supported LPS family product environment