eLabSDK.SampleLink
Classes
| Name | Description |
|---|---|
| eLabSDK |
Functions
| Name | Description |
|---|---|
| getSampleList(callback) | Retrieve all samples of the specified sample type that can be linked. |
This fetches the complete list of samples matching the configured sample type ID, using
pagination to retrieve all records. The method automatically handles multiple API requests
if needed to fetch all available samples. The sample list is returned via callback with
basic sample information (ID, name, etc.). Use this to populate sample selection lists,
enable sample linking workflows, or display available samples for relationship creation.
getSampleLink(linkedSampleID, callback) | Retrieve basic information for a linked sample.
This fetches the name and ID of a specific sample by its sample ID. Returns minimal sample
information via callback, suitable for displaying linked sample names or validating sample
references. Use this when you need quick access to a sample's basic identity without
fetching complete sample details.
getSampleInfo(linkedSampleID, callback) | Retrieve complete information for a linked sample including metadata and location.
This fetches comprehensive sample information including custom metadata fields, parent
sample relationships, and human-readable storage location. The location is automatically
resolved to a friendly format (e.g., "Box 3, Row A, Column 5"). Returns full sample
details via callback. Use this when you need detailed information about a linked sample
for display or processing purposes.
sendErrorMessage(message, callback) | Send an error message
copyLinkedSampleMetaFields(linkedSampleID, metaFieldsList) | Copy specific metadata field values from a linked sample to the current sample.
This retrieves metadata from the specified linked sample and copies values for the
specified fields to the current sample's form fields. The method automatically handles
different field types (text, combo/dropdown, radio buttons) and updates the UI
accordingly. Marks fields as changed to ensure values are saved. Use this to implement
"copy from linked sample" functionality or auto-populate fields based on relationships.
updateField(fieldLabel, fieldType, value) | Update the specified fields with their new value
eLabSDK
Kind: global class
new eLabSDK()
This is the description for my class.
getSampleList(callback)
Retrieve all samples of the specified sample type that can be linked.
This fetches the complete list of samples matching the configured sample type ID, using
pagination to retrieve all records. The method automatically handles multiple API requests
if needed to fetch all available samples. The sample list is returned via callback with
basic sample information (ID, name, etc.). Use this to populate sample selection lists,
enable sample linking workflows, or display available samples for relationship creation.
Kind: global function
| Param | Type | Description |
|---|---|---|
| callback | function | Callback function executed with the results |
| callback.result | Object | Result object containing sample data |
| callback.result.sampleList | Array.<Object> | Array of sample objects |
| callback.result.success | boolean | True if successful, false on error |
Example
// Get list of linkable samples
var sampleLink = new eLabSDK.SampleLink({
APIKey: 'your-api-key',
SampleTypeID: 123
}, currentSampleID);
sampleLink.getSampleList(function(result) {
if (result.success) {
console.log('Found ' + result.sampleList.length + ' samples');
result.sampleList.forEach(function(sample) {
console.log('- ' + sample.name + ' (ID: ' + sample.sampleID + ')');
});
} else {
console.error('Failed to retrieve samples');
}
});
Example
// Populate dropdown with linkable samples
var sampleLink = new eLabSDK.SampleLink({
APIKey: apiKey,
SampleTypeID: 456
}, currentSampleID);
sampleLink.getSampleList(function(result) {
if (result.success) {
var $select = $('#linkableSamplesDropdown');
result.sampleList.forEach(function(sample) {
var $option = $('<option></option>')
.val(sample.sampleID)
.text(sample.name);
$select.append($option);
});
}
});
getSampleLink(linkedSampleID, callback)
Retrieve basic information for a linked sample.
This fetches the name and ID of a specific sample by its sample ID. Returns minimal sample
information via callback, suitable for displaying linked sample names or validating sample
references. Use this when you need quick access to a sample's basic identity without
fetching complete sample details.
Kind: global function
| Param | Type | Description |
|---|---|---|
| linkedSampleID | number | The numeric ID of the linked sample to retrieve |
| callback | function | Callback function executed with the sample data |
| callback.result | Object | Result object containing sample information |
| callback.result.sample | Object | Sample object with name and ID |
| callback.result.sample.name | string | The sample's name |
| callback.result.sample.sampleID | number | The sample's ID |
| callback.result.success | boolean | True if successful, false on error |
Example
// Get linked sample name
var sampleLink = new eLabSDK.SampleLink({
APIKey: apiKey,
SampleTypeID: 123
}, currentSampleID);
var linkedSampleID = 456;
sampleLink.getSampleLink(linkedSampleID, function(result) {
if (result.success) {
console.log('Linked sample: ' + result.sample.name);
$('#linkedSampleName').text(result.sample.name);
} else {
console.error('Failed to retrieve linked sample');
}
});
Example
// Display multiple linked samples
var sampleLink = new eLabSDK.SampleLink(config, currentSampleID);
var linkedSampleIDs = [101, 102, 103];
linkedSampleIDs.forEach(function(linkedID) {
sampleLink.getSampleLink(linkedID, function(result) {
if (result.success) {
$('#linkedSamplesList').append(
'<li>' + result.sample.name + '</li>'
);
}
});
});
getSampleInfo(linkedSampleID, callback)
Retrieve complete information for a linked sample including metadata and location.
This fetches comprehensive sample information including custom metadata fields, parent
sample relationships, and human-readable storage location. The location is automatically
resolved to a friendly format (e.g., "Box 3, Row A, Column 5"). Returns full sample
details via callback. Use this when you need detailed information about a linked sample
for display or processing purposes.
Kind: global function
| Param | Type | Description |
|---|---|---|
| linkedSampleID | number | The numeric ID of the linked sample to retrieve |
| callback | function | Callback function executed with complete sample information |
| callback.sampleInfo | Object | Full sample information object |
| callback.sampleInfo.sampleID | number | The sample's ID |
| callback.sampleInfo.name | string | The sample's name |
| callback.sampleInfo.meta | Array.<Object> | Array of metadata field objects |
| callback.sampleInfo.parent | Object | Parent sample information if applicable |
| callback.sampleInfo.location | string | Human-readable storage location |
Example
// Get complete sample information
var sampleLink = new eLabSDK.SampleLink({
APIKey: apiKey,
SampleTypeID: 123
}, currentSampleID);
sampleLink.getSampleInfo(456, function(info) {
console.log('Sample: ' + info.name);
console.log('Location: ' + info.location);
console.log('Metadata fields: ' + info.meta.length);
// Display metadata
info.meta.forEach(function(field) {
console.log(' ' + field.key + ': ' + field.value);
});
});
Example
// Display linked sample details in UI
var sampleLink = new eLabSDK.SampleLink(config, currentSampleID);
sampleLink.getSampleInfo(789, function(info) {
var html = '<div class="sample-details">' +
'<h3>' + info.name + '</h3>' +
'<p><strong>Location:</strong> ' + info.location + '</p>';
if (info.parent) {
html += '<p><strong>Parent:</strong> ' + info.parent.name + '</p>';
}
html += '<h4>Custom Fields:</h4><ul>';
info.meta.forEach(function(field) {
html += '<li>' + field.key + ': ' + field.value + '</li>';
});
html += '</ul></div>';
$('#sampleDetailsContainer').html(html);
});
sendErrorMessage(message, callback)
Send an error message
Kind: global function
| Param | Type | Description |
|---|---|---|
| message | string | : error message |
| callback | function | : function to send the error message to |
copyLinkedSampleMetaFields(linkedSampleID, metaFieldsList)
Copy specific metadata field values from a linked sample to the current sample.
This retrieves metadata from the specified linked sample and copies values for the
specified fields to the current sample's form fields. The method automatically handles
different field types (text, combo/dropdown, radio buttons) and updates the UI
accordingly. Marks fields as changed to ensure values are saved. Use this to implement
"copy from linked sample" functionality or auto-populate fields based on relationships.
Kind: global function
| Param | Type | Description |
|---|---|---|
| linkedSampleID | number | The ID of the linked sample to copy metadata from |
| metaFieldsList | Array.<string> | Array of metadata field keys to copy |
Example
// Copy specific fields from linked sample
var sampleLink = new eLabSDK.SampleLink({
APIKey: apiKey,
SampleTypeID: 123
}, currentSampleID);
var linkedSampleID = 456;
var fieldsToCopy = ['Concentration', 'pH', 'Temperature'];
sampleLink.copyLinkedSampleMetaFields(linkedSampleID, fieldsToCopy);
console.log('Copying fields from sample ' + linkedSampleID);
Example
// Copy all fields from parent sample
var sampleLink = new eLabSDK.SampleLink(config, currentSampleID);
eLabSDK.Inventory.Sample.load(currentSampleID, function(currentSample) {
if (currentSample.parentSampleID) {
var allMetaFields = ['Field1', 'Field2', 'Field3', 'Field4'];
sampleLink.copyLinkedSampleMetaFields(
currentSample.parentSampleID,
allMetaFields
);
alert('Copied fields from parent sample');
}
});
Example
// Copy selected fields via button
var sampleLink = new eLabSDK.SampleLink(config, currentSampleID);
$('#copyFieldsBtn').on('click', function() {
var linkedID = parseInt($('#linkedSampleSelect').val());
var selectedFields = [];
// Get checked field checkboxes
$('.field-checkbox:checked').each(function() {
selectedFields.push($(this).val());
});
if (selectedFields.length > 0) {
sampleLink.copyLinkedSampleMetaFields(linkedID, selectedFields);
alert('Copied ' + selectedFields.length + ' fields');
}
});
updateField(fieldLabel, fieldType, value)
Update the specified fields with their new value
Kind: global function
| Param | Type | Description |
|---|---|---|
| fieldLabel | string | : Field label to copy the new value to |
| fieldType | string | : Field type to copy to (for now, only COMBO and TEXT supported) |
| value | string | : New field value |
© 2023 eLabNext
Updated about 3 hours ago