From 1a8025fb0a851ca470b49b262a8e4aa3eaac9bb0 Mon Sep 17 00:00:00 2001 From: suranofsky <50344679+suranofsky@users.noreply.github.com> Date: Sat, 6 Jun 2020 14:20:34 -0400 Subject: [PATCH] Tmp v12 (#5) * v12 enhancements * Update README.md * Update README.md --- Code.gs | 34 +++++++++++++++++++++++++--------- README.md | 11 ++++++++++- sidebar.html | 12 ++++++++++-- 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/Code.gs b/Code.gs index c88e779..3dc940d 100644 --- a/Code.gs +++ b/Code.gs @@ -46,6 +46,7 @@ function startLookup(form) { var startingRow = form.rowNumber; + var selectFirstRecord = form.selectFirstRecord; //SETUP SHEETS/TABS/RANGES TO READ FROM/WRITE TO var settingsTabName = form.tabSelection; @@ -71,6 +72,9 @@ function startLookup(form) { checkLocalCode = checkLocalHoldings.substring(x+1,checkLocalHoldings.length); } + //ADD THE ABILITY TO SEARCH BY ISSN + //SEARCH TYPE WILL BE ISBN OR ISSN + var searchType = dataSheet.getRange(1, 1).getValue().trim(); //FOR EACH ITEM TO BE LOOKED UP IN THE DATA SPREADSHEET: var lastRow = dataSheet.getLastRow(); @@ -87,9 +91,17 @@ function startLookup(form) { //VALUE IN THE LCCN COL. //IF THE ROW CONTAINS NEITHER IT MOVES TO THE NEXT ROW if (!isbnCell.isBlank()) { + //isbn could hold an issn or isbn depending on the column is labeled var isbn = isbnCell.getValue(); - if (isbn.length < 10) isbn = pad(10,isbn,0); - searchCriteria = "srw.bn=" + "%22" + isbn + "%22"; + if (searchType == "ISBN") { + //ISBN SEARCH + if (isbn.length < 10) isbn = pad(10,isbn,0); + searchCriteria = "srw.bn=" + "%22" + isbn + "%22"; + } + else { + //ISSN SEARCH + searchCriteria = "srw.in=" + "%22" + isbn + "%22"; + } } else if (!lccnCell.isBlank()) { searchCriteria = "srw.dn=" + "%22" + lccnCell.getValue() + "%22"; @@ -223,7 +235,7 @@ function startLookup(form) { //TO THE NEXT LOOKUP if (matchedTheCriteria == 0) { found = true; - matchFoundWriteResults(outputRange,dataFields,controlFields,dataRange,x,dataSheet); + matchFoundWriteResults(outputRange,dataFields,controlFields,dataRange,x,dataSheet,0); break; } @@ -231,10 +243,11 @@ function startLookup(form) { //ADDED 8/22/2019 //IF FOUND == FALSE & THE SEARCH FOUND AT LEAST ONE RECORD - USE THE TOP RECORD //IT WILL BE THE ONE WITH THE LARGEST NUMBER OF HOLDINGS - if (listOfRecords.length > 0 && found == false) { + //6-6-20 MAKING THIS CONFIGURABLE WITH A CHECKBOX + if (listOfRecords.length > 0 && found == false && selectFirstRecord == "true") { var dataFields = listOfRecords[0].getChild("recordData",nsp).getChild("record",slimNsp).getChildren("datafield",slimNsp); var controlFields = listOfRecords[0].getChild("recordData",nsp).getChild("record",slimNsp).getChildren("controlfield",slimNsp); - matchFoundWriteResults(outputRange,dataFields,controlFields,dataRange,x,dataSheet); + matchFoundWriteResults(outputRange,dataFields,controlFields,dataRange,x,dataSheet,0); } } @@ -250,7 +263,7 @@ function startLookup(form) { - function matchFoundWriteResults(outputRange,dataFields,controlFields,dataRange,rowNumber,dataSheet) { + function matchFoundWriteResults(outputRange,dataFields,controlFields,dataRange,rowNumber,dataSheet,recordCount) { var ui = SpreadsheetApp.getUi(); var colors = new Array(1); @@ -297,6 +310,9 @@ function startLookup(form) { //WRITE RESULTS var oneRowDataRange = dataSheet.getRange(rowNumber+1,outputColStart,1,outputRange.getNumRows()); oneRowDataRange.setValues(colors); + //6-6-20 - IF THERE WAS MORE THAN ONE LOCAL RECORD FOUND + //BOLD THE ROW + if (recordCount > 1) oneRowDataRange.setFontWeight("bold") } @@ -346,14 +362,14 @@ function startLookup(form) { var slimNsp = XmlService.getNamespace('http://www.loc.gov/MARC21/slim'); var root = document.getRootElement(); - var test = root.getChild("numberOfRecords",nsp).getValue(); - if (test == "1") { + var recordCount = root.getChild("numberOfRecords",nsp).getValue(); + if (recordCount > 0) { //FOUND A LOCAL RECORD, WRITE RESULTS TO THE SPREADSHEET var records = root.getChild("records",nsp); var listOfRecords = records.getChildren(); var dataFields = listOfRecords[0].getChild("recordData",nsp).getChild("record",slimNsp).getChildren("datafield",slimNsp); var controlFields = listOfRecords[0].getChild("recordData",nsp).getChild("record",slimNsp).getChildren("controlfield",slimNsp); - matchFoundWriteResults(outputRange,dataFields,controlFields,dataRange,x,dataSheet); + matchFoundWriteResults(outputRange,dataFields,controlFields,dataRange,x,dataSheet,recordCount); return true; } return false; diff --git a/README.md b/README.md index 574445a..a1ef3a1 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ I collaborated on this project with Lehigh's Cataloging/Metadata Librarian, Lisa

We co-presented a session about this project to the ALA Technical Services Workflow Efficiency Interest group during the American Library Association's 2019 annual conference. You can view our slides here: https://connect.ala.org/HigherLogic/System/DownloadDocumentFile.ashx?DocumentFileKey=3a69473d-a4a3-4781-a546-72b394ef3886

-We are co-authoring an article about the project which will be published in the November 2019 issue of the code4lib journal. +We co-authored this article about the project in the November 2019 issue of the code4lib journal:
+https://journal.code4lib.org/articles/14813

This add-on is publicly available using the “Add-ons > Get add-ons” menu in any Google Sheet. A search for MARC will show the add-on.

@@ -13,6 +14,14 @@ https://gsuite.google.com/marketplace/app/matchmarc/903511321480 # Versions + +### 6-6-2020 +### Version 12 +## New Features and Fixes +1) If it finds duplicate local holdings, it will select one and bold the row so you know it found a duplicate +2) If no match is found, it will select the top match (with the most holdings) only if you check the box: Select first record when no match? +3) New ISSN Search: If you label row one, column one "ISBN" it will search by ISBN. If you label row one, column one "ISSN" it will search by ISSN + ### 2-7-2020 ### Version 11 ## New Features: diff --git a/sidebar.html b/sidebar.html index 732b0b8..4f6d0dc 100644 --- a/sidebar.html +++ b/sidebar.html @@ -37,6 +37,14 @@
+ Select first record when no match? +
+
+ +
+
+ + Start search at row#
@@ -91,9 +99,9 @@
- v. 11 + v. 12
- See details about v. 11 in github + See details about v. 12 in github