Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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:

     

    Info
    titleSample Image Selection Script
    //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.

    Info
    titleSample Image Selection Script
    //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 = "";
    }
Info
Refer to the attached label that contains the above this solution.   : Article-2016013.lwl

Content by Label
spacesLPSKB
reversetrue
max5
sortmodified
labelsimage script scripting logic kb-how-to-article
showSpacefalse
typepage

Article Number

2016013

Versions

 LPS 9.5.2 and higher

Environment

Any supported LPS family product environment

Page properties
hiddentrue

This table provides article information that is only visible to Loftware users.

Linked Jira

JIRA
serverJira
serverIdb694bd2b-f495-3baf-a460-a9c93a1d1de3
keyOOB-789

 
JIRA
serverJira
serverIdb694bd2b-f495-3baf-a460-a9c93a1d1de3
keyOOB-981
Author

Charles Wilkinson 

Michael W. Vachon

Incident/Case Number 
Review DateJune 22, 2017