---
title: "system.mes.spc.sample.collect(defName, locationPath, [attributeData], [factorData], [takenBy], [note], [approved], [refNo], [tag], [productCode], [entryDateTime], [sampleTakenDateTime])"
id: "system-mes-spc-sample-collect-defname-locationpath-attributedata-factordata-takenby-note-approved-r"
project: "MES User Manual"
url: "https://docs.sepasoft.com/articles/user-manual/system-mes-spc-sample-collect-defname-locationpath-attributedata-factordata-takenby-note-approved-r"
updated: 2026-07-31T14:59:22Z
---

# system\.mes\.spc\.sample\.collect\(defName, locationPath, \[attributeData\], \[factorData\], \[takenBy\], \[note\], \[approved\], \[refNo\], \[tag\], \[productCode\], \[entryDateTime\], \[sampleTakenDateTime\]\)

**Sepasoft MES Module Suite**

### system.mes.spc.sample.collect(defName, locationPath, [attributeData], [factorData], [takenBy], [note], [approved], [refNo], [tag], [productCode], [entryDateTime], [sampleTakenDateTime])

Collects a sample in a single method call without needing to create or update a sample instance. This function accepts keyword arguments.

| ![Warning](/resources/Storage/user-manual/user-manual/Warning.png) | **Scripting Function modifications in**<br><br>MES 3.79.3 RC 5 and later<br>MES 3.81.4 RC 5 and later |
| --- | --- |

Syntax

system.mes.spc.sample.collect(**defName, locationPath, [attributeData], [factorData], [takenBy], [note], [approved], [refNo], [tag], [productCode], [entryDateTime], [sampleTakenDateTime]**)

* Parameters

String **defName** - Existing sample definition name to base the new sample on.

String **locationPath** - A valid path to a location to base the new sample for.

PyDictionary **attributeData** - Optional Argument. A python dictionary where the key is the attribute name. The value can be a value or an array of values where each one is another measurement. A dictionary can be used in place of a primitive value with keys 'value', 'note', and 'cause'.

PyDictionary **factorData** - Optional Argument. A python dictionary where the key is the factor name (String) and the value should be a primitive value like a number, string, or boolean value.

String **takenBy** - Optional Argument. The username of the user that recorded this sample.

String **note** - Optional Argument. A note to attach to the sample.

Boolean **approved** - Optional Argument. If the sample should be approved or not, this overrides the locations default auto-approve setting.

String **refNo** - Optional Argument. A string value that can be used for grouping samples.

String **tag** - Optional Argument. A string value that can be used for grouping samples.

String **productCode** - Optional Argument. A string value to set as the sample Product Code.

Date **sampleTakenDateTime** - Optional Argument. A date value for when the sample was taken. Defaults to current time. **MES 3.79.3 RC 6 and later | MES 3.81.4 RC 6 and later**

Date **entryDateTime** - A date value for when the sample was entered. This date is used to calculate coming due/due/overdue state. Defaults to current time. **MES 3.79.3 RC 6 and later | MES 3.81.4 RC 6 and later**

* Returns

Nothing

* Scope

All

Code Examples


```python
##Sample data collected through script, tags, on-screen bindings, etc. and placed in a dictionary for collection function call.
dataDict = {'attribute1':0.08,'attribute2':3.14159,'attribute3':6875309}

##Determine the Sample Location where the collection event occurs.
location_path = "Enterprise\Site 1\Area 1\Location 1"

##Current timestamp provided as an example.  If the sample was collected in the past, provide that timestamp instead.
timestamp = system.date.now()

##Call the Collect Sample function, providing appropriate optional parameters per the scenario. 
system.mes.spc.sample.collect('DimensionData', location_path, dataDict, sampleTakenDateTime=timestamp)


```


**Sepasoft MES Module Suite**