Skip to main content
ExLibris
  • Subscribe by RSS
  • Ex Libris Knowledge Center

    Drools Normalization - Copy exact positions of a controlfield to a datafield

    Created By: Obv- alma
    Created on: 8/06/2018

    Question

    How can I copy the language code from controlfield 008 Pos. 35-37 to datafield 041 subf. a?

    Answer

    This can be achieved by a trick using Drools Normalization:

    rule "copy 008 language code to 041 if 041 does not exist"
    when
    ((not exists "041.a") AND (not existsControl "002"))
    then
    copyControlField "008" to "002"
    replaceControlContents "002.{0,35}" with " "
    replaceControlContents "002.{4,2}" with " "
    copyField "002" to "041.a"
    removeField "002"  
    end
    

    Additional Information

    First the whole controlfield 008 is copied to another controlfield (in this example 002) which is NOT in use.
    Next two lines are the crucial ones - we have to isolate the language code (pos. 35-37) from the rest of the controlfield, because we only want to copy the language code and not the whole field. Therefore we replace the contents of all positions except 35-37 with blanks.
    The remaining content is then copied to 041 subf. a.
    As a last step we remove controlfield 002.