Home
  • Sign up for FREE
  • How It Works
  • Member Sign In

  • Cataloging Documentation Center
  • Overview

Macros

Using and creating macros to operate on MARC records

‡biblios.net has the capability to run macros (a sequence of record-altering steps) on bibliographic records.  An example of a macro could be one which changes a record's title (245 field, subfield $a for MARC21 records) to 'New title here':

record.field('245').subfield('a', 'New title here');

The syntax used by the macros is plain Javascript.  Available to the macro is an implicit MarcRecord object (see below) which refers to the current record being acted upon.

The Javascript objects available to the macro are the following:

MarcRecord

API for working with fields

  • MarcRecord( [array of Field objects] )
  • record.field( fieldnumber )
  • record.fields()
  • record.addField( field )
  • record.removeField( fieldnumber )
  • record.hasField( fieldnumber )

Field

  • Field(tagnumber, indicator1, indicator2, [array of Subfields]); // pass in strings for tagnumber, ind1, ind2 and an array of subfields
  • field.indicators()
  • field.indicator(number, value)
  • field.tagnumber()
  • field.addSubfield( Subfield )
  • field.removeSubfield( subfieldcode )
  • field.hasSubfield( subfieldcode )
  • field.subfields()
  • field.XML()
  • field.XMLString()


Subfield

  • Subfield(code, value)
  • subfield.setCode( code )
  • subfield.getCode()
  • subfield.setValue( value )
  • subfield.getValue( value )


Working with XML

  • record.XML() 
  • record.XMLString()
  • record.loadMarcXml( xmldoc )


Usage

creating a new MarcRecord object and using its methods:

var record = new MarcRecord( [array of Fields] );
record.addField( new Field('999', '', '', [ new Subfield('a', 'local stuff here') ]) );
record.hasField('999'); // returns true
record.removeField('999'); // returns true and removes 999 field
record.fields(); // returns array of fields in this marc record
record.field('999'); // returns Field object
record.XML(); // returns an XML document object representing this marc record
record.XMLString(); // returns a string representation of the XML for this marc record
record.loadMarcXml( xmldoc ); // loads a MARCXML document into this marc record

TIP: Note that when running a macro, there will already be a MarcRecord object available, called "record".

 

Examples of macros

Adding an institution code to 040
record.field('040').addSubfield( new Subfield('d', 'BIBLIOS') );

Adding a 999 field with subfield $a
record.addField( new Field('999', '', '', [ new Subfield('a', 'local note here') ]) )

Check to see if record has 856.  If so, add $u with url.  If not, create 856 with url.
if( record.hasField('856') ) {
    record.field('856').subfield('u', 'http://www.google.com');
}
else {
    record.addField( new Field('856', '', '', [ new Subfield('u', 'http://www.google.com')]) );
}

Creating macros

To add a macro to ‡biblios.net you will need to open the macros menu by clicking on Options > Macros

  • Click the "Add Macro" button to add a new macro to the current list of macros.
  • Double click in the Name field to give the macro a name. 
  • In the "Code" field, enter the Javascript code for the macro (see above).
  • Choose Enabled to enable the macro.


Using macros
You can run a macro either on a series of records in a Folder, or on an open record in the editing screen.

Running a macro on records in a Save Folder

  • To run a macro on a series of records in a Folder, first click on the Folder containing the records.
  • Then check the checkboxes next to the records you want to run the macro on.
  • Then go to Tools->Macros and choose the macro you wish to run (displayed by macro name).
  • The macro will run on each successive record, executing the Javascript code in the macro's "code" field.  For each record, the "record" object refers to the current record being operated upon.


Running a macro on a record open in the MarcEditor
When a record is open in the editor window, you may run a macro on it by going to Tools->Macros and selecting the macro to be run.  The macro's "code" field will be executed, with the "record" object referring to the currently open record.

 

Help Resources

Cataloging 101 Forum
Advanced Cataloging Topics Forum
Known Issues
Paid Support Options

 



  • Copyright © 2008 LibLime
  • Terms of Service
  • Privacy