Ready to Learn?Ex Libris products all provide open APIs

Tech Blog

 

Populate Replacement Cost

Meredith Foster on September 24th, 2018

The following application allows a user to fill in the Replacement Cost field in an Alma item record from the total price in the associated purchase order.

The code is written in Python version 3, and requires the Tkinter standard module.  On some platforms, Tkinter is not included with the distribution and needs to be installed separately.  A compiled Windows executable is also provided to allow use on workstations without the Python development environment installed.

In order to use the application, an API key must be created first.  The API key uses the Acquisitions API set to production read-only, and the Bibs API set to production read/write.

Replacement Cost API Settings

Download one of the following links to obtain the code.
Python Source Code
Windows Executable

Unzip the code or executable and edit the ReplacementCost.ini file.  Copy the API key that was created for the application above into the api_key field in ReplacementCost.ini.  Choose one of the api_host options, depending on your institutional geographic region, commenting out any other with a semicolon.  The font settings can also be edited, as the defaults are larger than normal for visibility.

Run ReplacementCost.pyw or ReplacementCost.exe.  A window is opened that allows a user to scan a barcode or to select a file of barcodes to process.

The first time used, it is recommended to operate interactively and make sure that nothing unexpected is changed in the item records, before using it in batch mode.

To operate interactively, scan or type a barcode into the text field at the top of the screen.  Press enter or click Process Barcode if the barcode scanner does not send a "return/enter" automatically.  To operate in batch mode, click the "Load Barcode File" in the top right, and select a file of barcodes to use.  The barcode file should be a text file with one barcode per line.  A header should not be included, and blank lines are skipped.

The script operates by the following rules:

  • A barcode that is not found using the provided API key will write an error message to the log part of the application window and wait for the next entry.  An incorrect API key will trigger this message as well.
  • If the item record found by the barcode exists, and already contains data in the Replacement Cost field, alert the user and wait for the next entry.
  • If an item record was found, does not have a replacement cost, and does not have a PO line associated, alert the user and wait for the next entry.
  • Call the Analytics API using the PO line reference number from the item record, and check for a total price.  Alert the user if no total price was found.
  • If a total price was found, take the item record retrieved earlier, add a replacement cost tag with the total price from the PO, and write it back to Alma using the Bibs API.
  • Once the total price was written, notify the user if the values 0.01 or 1.0 (in US terms, 1 cent and 1 dollar) were written, as there may be some issue with that purchase order line.

One warning is that the Alma Bibs API does not include select fields when performing an item lookup if the field is empty in Alma.  When the item is written back to the Bibs API, those fields that were left out will be set to default values.  The "Is Magnetic" field is one such field, if the item record does not have that field set, it will not be included in the API lookup and will be overwritten by the default value "No" when the edited item record is written back through the API.  Other fields may have the same issue.  When using this script, check your items carefully the first few times it is run to be sure nothing unexpected is changed.

Replacement Cost Window