eLabSDK.Page.EquipmentEditor

.addMeta(type, key, value, [metaIndex], [skipRefreshTable])

Add or update a metadata field value in the equipment editor.

This static method programmatically sets the value of a metadata field in the equipment editor
form. The field is identified by its key, and the value is set according to the field type
(text, combo, etc.). By default, the metadata table is refreshed after the update to reflect
the change visually. Use this to pre-populate equipment metadata, set calculated values, or
automate data entry in the equipment editor.

Kind: static function

ParamTypeDefaultDescription
typestringField type (e.g., 'TEXT', 'COMBO', 'DATE', 'NUMBER')
keystringThe metadata field key/identifier
value*The value to set for the field
[metaIndex]numberOptional index of the metadata field
[skipRefreshTable]booleanfalseIf true, skip refreshing the metadata table display

Example

// Set equipment metadata from custom logic
eLabSDK.ready(function() {
  var editor = new eLabSDK.Page.EquipmentEditor({
    onSave: function(data) {
      // Validation logic
      return true;
    }
  });
  
  // Automatically set calibration date to today
  var today = new Date().toISOString().split('T')[0];
  eLabSDK.Page.EquipmentEditor.addMeta('DATE', 'CalibrationDate', today);
});

Example

// Set multiple metadata fields
eLabSDK.ready(function() {
  var editor = new eLabSDK.Page.EquipmentEditor();
  
  // Set multiple fields at once (skip refresh until last one)
  eLabSDK.Page.EquipmentEditor.addMeta('TEXT', 'Manufacturer', 'Acme Corp', null, true);
  eLabSDK.Page.EquipmentEditor.addMeta('TEXT', 'Model', 'XYZ-2000', null, true);
  eLabSDK.Page.EquipmentEditor.addMeta('NUMBER', 'SerialNumber', '12345', null, false);
  // Last one refreshes table
});

Example

// Populate from external system
eLabSDK.ready(function() {
  var editor = new eLabSDK.Page.EquipmentEditor();
  
  $.get('/api/equipment/external/456', function(externalData) {
    eLabSDK.Page.EquipmentEditor.addMeta('TEXT', 'ExternalID', externalData.id);
    eLabSDK.Page.EquipmentEditor.addMeta('TEXT', 'LastSync', new Date().toISOString());
    eLabSDK.Page.EquipmentEditor.addMeta('TEXT', 'SyncSource', 'External System');
    
    console.log('Equipment metadata populated from external system');
  });
});

Example

// Set calculated value
eLabSDK.ready(function() {
  var editor = new eLabSDK.Page.EquipmentEditor({
    onSave: function(data) {
      // Calculate next calibration date
      var lastCalibration = new Date(data.CalibrationDate);
      var nextCalibration = new Date(lastCalibration);
      nextCalibration.setFullYear(nextCalibration.getFullYear() + 1);
      
      // Set calculated value
      eLabSDK.Page.EquipmentEditor.addMeta(
        'DATE',
        'NextCalibrationDue',
        nextCalibration.toISOString().split('T')[0]
      );
      
      return true;
    }
  });
});

© 2023 eLabNext