When you print labels using the File > Print label option or the Print label button in the Start menu of Adlib, you print to printer-specific labels (using printer-specific templates, not Word templates) which may contain fixed texts, barcodes and field data from your Adlib records. From Adlib 7.4, these label templates come in two varieties, an .lbl (from 7.2) and an .lbx/.lbr variety (see the installation guide for Museum, Library and Archive for more information about these formats and their differences). With both formats it is possible to have a custom adapl preprocess any record data before a label is printed. You could use this functionality to have more control over how names of persons or institutions will be printed on your labels, for instance by dynamically limiting the length of data to be printed or to rearrange the order of printed details depending on what data is actually present in the record. And in the more advanced .lbx/.lbr variety you could have the adapl also change your initial record selection conditionally by adding or removing records to or from that selection, for instance because you don’t want the marked parent record to be printed but all its child records instead. Moreover, you can let an adapl for the .lbx/.lbr variety dynamically select an appropriate template to print to, based on the contents of the currently processed record: for example, you could have the adapl automatically use a template with a smaller font to print a long text, or let the adapl split up a long title in two parts to print that record to a label template which has actually been set up to print long titles over two lines.

All functionality of ADAPL is at your disposal, but do not use ERRORM or PRINT commands: only use this type of adapl to temporarily change certain data and/or to fill temporary fields with new data, preceding the automatic print process. A reference to the adapl to be used must be included in the .lbl label template itself or in the .lbx configuration file.

An adapl associated with an .lbl template will be executed for each marked record while an adapl referenced in an .lbx configuration file will first be executed for the record selection as a whole and subsequently for each marked record. Whilst it is being executed for an individual marked record (not for the record selection as a whole), it has direct access to all data (by means of the field tags, no need to use FACS) from the currently processed record. In the adapl you must use field tags while in the label template typically field names* will be used; Adlib will match the tag to the proper field name before printing. For example: assume that you've used the name field in your label template and that this field contains person names in the format ‘surname, first name’, and you would like to reverse this to ‘first name surname’ using an adapl. The tag of the name field would be %1. Then for an .lbl template you could write the following very simple adapl to handle this:
 

* this adapl reverses 'surname, first name'
* to 'first name surname'.
%1 = name$(%1)
end

For an adapl referenced in an .lbx file, you would need to extend this code to the following to make sure it wouldn't be executed during its first run for the record selection as a whole:

* this adapl reverses 'surname, first name'
* to 'first name surname'.
if (&1[2] = 13) { /* execute during individual record processing only
  %1 = name$(%1)

}
end

 

You can even use temporary tags in your adapl and template (although you should still register any temporary tags in the data dictionary). Suppose tag yy does not appear in your database, then in your adapl you could fill this temporary tag with any value you like, subsequently include the tag in the template like you would with a normal field name or tag and the value will be printed. For example, to fill tag yy with today’s date, add the following line to your adapl: yy = date$(8)

Note that changes to fields or temporary tags won't be stored in the database record.

* In the label template you can use field tags instead of the English field names if you find that to be more clear, but you can’t use tags starting with a percent character. So in the relevant field reference in a template using the above adapl you would have to use the field name instead of the field tag.

Applicable system variables for the .lbx/.lbr variety

Only for the .lbx/.lbr variety, a number of system variables can be used to obtain information from and if desired to write new values to, to expand your label printing functionality substantially. The following system variables can be used:

Available during preprint (processing record selection)

Tag

Type

Information

&1

numeric

Will contain execution code 8 (adapl called from print function).

&1[2]

numeric

Will contain execution sub code 12 (adapl called when processing the initial record selection as a whole: this is the first adapl run).

&A

text

The name of the print job (as it appears in the printer queue). Modify this string to change the name of the print job.

&B

numeric

Number of records in the initial record selection.

&I

numeric

The serial number (not the record number) of the currently processed record. Will always be zero during preprinting.

&I[2]

numeric

Contains a boolean value, 0 by default:

1 = hide Select template variation dialog in Adlib for Windows.
0 = show Select template variation dialog in Adlib for Windows.

So if you don't want the template files referenced by the .lbx file to appear in the Select template variation dialog after selecting the label group title in Adlib, set &I[2] = 1 in the preprint section of the adapl.

&I[3]

numeric

Contains a boolean which functions as the record selection switch: the initial record selection is kept in system variable &S while an adjusted record selection can be stored in system variable &R. The boolean defaults to 0, meaning that the unchanged record selection from &S will be used for printing, while 1 means that you'd like the alternate record selection that you stored in &R to be used for printing. Simply set &I[3] = 1 in the preprint section to print your adjusted record selection from &R.

&P

numeric

The current user-interface language number in Adlib for Windows.

&R[]

numeric

The final list of records to print. If it is not self-evident that the adapl must print the records from the initial selection, because you might want to add or remove records to or from the selection conditionally, then write the record numbers of the desired selection in subsequent occurrences of this system variable. &R is a one-dimensional numeric array, so to fill the third occurrence with record number 10345, you would write &R[3] = 10345

&S[]

numeric

The read-only, initial selection of marked records. &S is a one-dimensional numeric array containing the record numbers of the record set. For example, &S[4] would yield the fourth record number from the array.

 

Available during printing (processing single records)

Tag

Type

Information

&0

numeric

Number (priref) of the currently processed record.

&1

numeric

Will contain execution code 8 (adapl called from print function).

&1[2]

numeric

Will contain execution sub code 13 (adapl called when processing an individual record from the final record selection).

&6[1]

text

Name of database in which the record is located that the user has opened.

&6[2]

text

Name of dataset in which the record is located that the user has opened.
Names are case-sensitive.

&6[3]

text

Path to the database in which the record is located that the user has opened.

&A

text

The name of the print job (as it appears in the printer queue). This name cannot be modified during printing of individual records.

&A[2]

text

The template variation ID. This important system variable lets the adapl set the template to use for printing. Simply assign the desired template ID (as specified in the .lbx file) to &A[2], like &A[2] = 'two-line' for example. You can change this assignment per printed record.

&A[3]

text

If the adapl skips a record during printing, it can write the rejection reason in this system variable. Also see &I[4].

&B

numeric

Number of records in the final record selection. This final record selection may come from either &S or &R. Use &I[3] in the preprint section to specify which one to use.

&I

numeric

The serial number (not the record number) of the currently printed record in the final record selection. The variable starts at 1 and counts up with every processed record.

&I[4]

numeric

Boolean record skip flag, defaults to 0.  Set it to 1 to prevent the currently processed record from being sent to the printer queue.
So there are two ways of filtering records to be printed, by specifying an altered record selection in &R (in the preprint section) and by skipping records in the printing section, using &I[4] = 1

&P

numeric

The current user-interface language number in Adlib for Windows.

&T[1]

text

Date on which current record was last edited.

&T[2]

text

Time at which current record was last edited.

&T[3]

text

Date on which current record was created.

&T[4]

text

Time at which current record was created.

&X[]

text

&X is a variable text array that allows the adapl to store multiple texts in its occurrences that can be referenced in the .lbr template(s) as if they were fields to print. This allows you to print altered data without having to store it in temporary tags. So you could write something like &X[1] = 'AB107' and &X[2] = 'VDF9' and reference &X[1] and &X[2] in .lbr templates using %rtagv:X[1]% and
%rtagv:X[2]%

An example of an adapl putting some of the listed system variables to good use, is the following. It does two things: first it changes the initial record selection to a final record selection and then it decides per processed record to which of two templates the record data must be printed (based on the length of the title stored in the record) and it simultaneously splits up a long title into two parts if the length of the title requires it.

* copyright 2017 Axiell ALM Netherlands B.V

fdstart COLLECT '../data+collect'
 %0 is objectPriref
 IN is objectNumber
 nr is objectNarrowers
 rT is objectType
fdend

open COLLECT
if (&e) {
errorm 'The COLLECT database could not be opened (error ' + &e + ').'
end
}

integer i                            /* generic counter
integer j                            /* generic counter
integer narrow_count                 /* number of narrowers in part record
integer total_records                /* total records to print
integer back_length                  /* the length of the second line after splitting
integer field_length                 /* the label field length, used for splitting
integer split_position               /* the position at which to split the first line
integer blankspace_search_range      /* how many characters to search when splitting a line
text field_text[0]                   /* the text to split and insert into the template

 

if (&1[2] = 12) {          /* If this adapl is executed for the initial record selection (first run)
 i = 1  
 total_records = 0
 &I[2] = 1             /* hide "Select template variation" dialog in Adlib for Windows
 while (i <= &B) {     /* do as many times as there are records in the initial selection
      /* Show dynamic progress message containing the processed record number
   milestone ('Preparing, please wait.', 'Processing record...', INT(val(&S[i])))
   read COLLECT using objectPriref = &S[i]   /* Read a record by means of a priref from &S
   if (&E = 0) {                             /* If successful...
          if (enumcode$(objectType[1]) = 'MAIN') {  /* If this is a parent record
            narrow_count = repcnt(objectNarrowers)  /* Count its linked children
            j = 1
            while (j <= narrow_count) {             /* do for all children
                  total_records = total_records + 1    /* increment total_records counter
                  &R[total_records] = val(objectNarrowers[j])    /* add numerical child priref to
                                                               /* final record selection array
                  j = j + 1
            }
          } else {                                                                
            if (enumcode$(objectType[1]) = 'PART') {          /* Else if this is a child record
                  total_records = total_records + 1              /* increment total_records counter
                  &R[total_records] = val(objectPriref)          /* add numerical priref to
                                                               /* final record selection array
            }  
          }
   }
   i = i + 1
 }
 milestone ('', '', -1)
 &B = total_records         /* Change &B to the number of records in the final record selection
 &I[3] = 1                  /* Instruct Adlib to print the records from the &R array: this is
                               /* now the final record selection
 

 if (total_records = 0) {
         errorm 'No record(s) to print. You can only use this label to print main or part records.'        
 }
}

 

* If this adapl is executed per record of the final record selection (second and following runs)
if (&1[2] = 13) {

 /* This section checks the length of the data in
 /* a title and breaks it up into two lines if the title
 /* is too long. It also selects the right template variation.
 /* Template variations must have been specified in the .lbx
 /* configuration file in which this adapl must also be referenced.
 /* The my-single-line-template template must contain at least a
 /* field reference to X[1], while the my-two-line-template template
 /* should at least contain field references to X[1] and X[2], to
 /* print the title.
 /* See the general installation guide for Adlib for more information
 /* about creating label templates and an .lbx configuration file.
 

 field_text = ti                      /* Copy title to variable
 field_length = 32                    /* Set max number of printable characters in single line
 blankspace_search_range = 10         /* Set number of characters to look for a space
 if (len(field_text) <= field_length) {     /* if title is not too long
         &A[2] = 'my-single-line-template'    /* Set the ID of the template to use
         &X[1] = field_text                   /* Fill first occurrence of &X array with title
 } else {                                  /* else if title too long
         if (len(field_text) > 52){           /* If title is longer than 52 characters
                 field_text = left$(field_text, 52)  /* Cut off title to 52 characters
         }
         gosub 100
         &A[2] = 'my-two-line-template'             /* Set the ID of the template to use
         &X[1] = left$(field_text, split_position)  /* Assign first part of title to &X[1]
         &X[2] = right$(field_text, back_length)    /* Assign second part of title to &X[2]
 }
}
end  

 

100
* Find split position in long title by looking for a space in that title,
* starting at position 32 going down to 22. If we can't find a space in those 10 characters
* then set the split position to 32.

j = field_length
split_position = field_length
while (j > (field_length - blankspace_search_range)) {
 if (mid$(field_text, j, 1) = ' ') {
         split_position = j
         j = 1
 }
 j = j - 1
}
back_length = (len(field_text) - split_position)
return