Example 7: Update records
Note: When you construct your Import data file to update records and include a Column Name but do not associate a value with it, any existing value in that field in EMu will be removed when the Import is run. This can be useful if you wish to clear any existing values from a particular field. However it can also be potentially dangerous as you could inadvertently clear a field of all values.
In this example the Import tool is used to update records in EMu. Updating records only requires that a unique field (or combination of unique fields) is used to identify an existing record. Another way of expressing this is that if a unique field (or combination of unique fields) is present in the Import data file and there is a matching record, the matching record will be updated rather than a new record being created.
Uniqueness is determined by a combination of two conditions. Both must be met:
- The field must be specified as unique in the back-end.
Every module has at least one field that is specified as unique in the back-end by default: IRN.
The Unique attribute can be set using the Unique Index Indexing Registry entry.
- The Unique Strict Registry entry must be specified for each of these unique fields (except for IRN).
Unique Strict specifies whether a field should be checked for uniqueness as a new record is being processed or existing record is being edited. Typically the check occurs as a field is exited (displaying a warning if it is a duplicate), but in the case of the Import Tool, as each record is being processed.
Note: For multi-column unique values (where a combination of fields is used to specify uniqueness) it is necessary to set Unique in the back-end and specify Unique Strict in the Registry for each of the fields.
This example uses IRN as well as Accession Number to identify records in the Catalogue module and update a located record's Condition fields: if unique fields are specified in the data file and a matching record is identified in EMu, the EMu record is updated.
Note that if a record with a unique field specified in the data file does not exist in EMu, it will be created.
Note: In this example, the updates will only work if Accession Number has been set up as a Unique field in the Catalogue.
Note: Unique fields cannot themselves be updated.
Rules
- Where a record in the Import data file matches an existing EMu record and the matching data is in one or more fields configured to be unique (e.g. an IRN), the record is updated.
- If a Column Name is included in the Import data file, but no value is associated with it, any existing value in the field will be removed from the matching EMu record when the import is run.
This can be useful if you wish to clear any existing values from a particular field. However it can be potentially dangerous as you could inadvertently clear a field of any values.
- If a record in the Import data file includes a field configured in EMu to be unique (e.g. an IRN) and there is no matching record, a new record is created.
- If a record in the Import data file includes a field configured in EMu to be unique (e.g. an IRN) and there is more than one match, an error is generated.
- Unique fields cannot themselves be updated.
In this example the fields used are:
Fields |
Back-end name |
---|---|
IRN | irn |
Accession Number | TitAccessionNo
|
Condition Status | ConConditionStatus
|
Date Checked | ConDateChecked
|
Checked By | ConCheckedByRef
|
Condition Details | ConConditionDetails
|
For display purposes only, the import data below is presented with column headings listed vertically rather than horizontally. The first row of any tab or comma delimited file must include the column names. The appropriate layout is:
irn
|
TitAccessionNo
|
ConConditionStatus
|
484
|
Excellent | |
1996.011.042
|
Poor | |
1995.112.061
|
Good |
The import data is:
Column Name (must appear as the first row of the import data file) |
Record 1 |
Record 2 |
Record 3 |
---|---|---|---|
irn
|
484
|
|
|
TitAccessionNo
|
|
1996.011.042
|
1995.112.061
|
ConConditionStatus
|
Excellent | Poor | Good |
ConDateChecked
|
15-Aug-05 | 16-Aug-05 | 17-Aug-05 |
ConCheckedByRef.NamFirst
|
Joe
|
Joe
|
Joe
|
ConCheckedByRef.NamLast
|
Jackson
|
Jackson
|
Jackson
|
ConCheckedByRef.NamRoles_tab(1)
|
Condition Checker | Condition Checker | Condition Checker |
ConConditionDetails
|
The work is in excellent condition.Loans can be approved (subject to normal conditions). | Due to the poor condition of this work, loans should not be approved. |
|
irn
and TitAccessionNo are both unique fields in this Catalogue; when the import data file is processed, if a record is found with a matching IRN or Accession Number, it will be updated. If no matching record is found, one will be created using the values provided.
The XML for this example is:
<?xml version="1.0" encoding="UTF-8"?>
<table>
<!--First record -->
<tuple>
<atom name="irn">484</atom>
<atom name="ConConditionStatus">Excellent</atom>
<atom name="ConDateChecked">15 August 2005</atom>
<tuple name="ConCheckedByRef">
<atom name="NamFirst">Joe</atom>
<atom name="NamLast">Jackson</atom>
<table name="NamRoles_tab">
<tuple>
<atom>Condition Checker</atom>
</tuple>
</table>
</tuple>
<atom name="ConConditionDetails">The work is in excellent condition.
Loans can be approved (subject to normal conditions).</atom>
</tuple>
<!--Second record -->
<tuple>
<atom name="TitAccessionNo">1996.011.042</atom>
<atom name="ConConditionStatus">Poor</atom>
<atom name="ConDateChecked">15 August 2005</atom>
<tuple name="ConCheckedByRef">
<atom name="NamFirst">Joe</atom>
<atom name="NamLast">Jackson</atom>
<table name="NamRoles_tab">
<tuple>
<atom>Condition Checker</atom>
</tuple>
</table>
</tuple>
<atom name="ConConditionDetails">Due to the poor condition of this work, loans should not be approved.</atom>
</tuple>
<!--Third record -->
<tuple>
<atom name="TitAccessionNo">1995.112.061</atom>
<atom name="ConConditionStatus">Good</atom>
<atom name="ConDateChecked">15 August 2005</atom>
<tuple name="ConCheckedByRef">
<atom name="NamFirst">Joe</atom>
<atom name="NamLast">Jackson</atom>
<table name="NamRoles_tab">
<tuple>
<atom>Condition Checker</atom>
</tuple>
</table>
</tuple>
</tuple>
</table>