# Workflow sample

here is a basic sample how to process data and report processing back into the data interface:

```sql
-- a variable to store the bulk ID currently being processed by your system 
DECLARE @BulkId INT = -1;

-- a variable to store the EcENTITY.id of the top entity within the current bulk ID 
DECLARE @EntId BIGINT = -1;

-- get the next pending bulk ID (data waiting to be processed by your system):
SET @BulkId = (SELECT TOP 1 bulk_id FROM EcENTITY WHERE comm_dir=0 AND comm_status=0 ORDER BY id)

-- update comm_status – the bulk processing has started
UPDATE EcENTITY SET comm_status = 1, processed1=GETDATE() WHERE bulk_id = @BulkId

-- get the top entity of the bulk structure
SET @EntId = (SELECT TOP 1 id FROM EcENTITY WHERE bulk_id=@BulkId AND EcENTITY.id NOT IN (SELECT
EcASSOC.ent_id_child FROM EcASSOC))

-- get a list of associations for the top entity – first level associations 
SELECT * FROM EcASSOC WHERE ent_id_parent=@EntId;

-- get a list of links for the top entity 
SELECT * FROM EcLINK WHERE ent_id=@EntId;

-- get a list of child entities in the first level
SELECT * FROM EcENTITY WHERE EcENTITY.id IN (SELECT ent_id_child FROM EcASSOC WHERE
ent_id_parent=@EntId);

-- XXXXXXXXXXXXXXXXXXXXXXXXXXX
-- write data into your system
-- XXXXXXXXXXXXXXXXXXXXXXXXXXX

-- report the bulk as successfully processed by your system

UPDATE EcENTITY SET comm_status = 7, processed2=GETDATE() WHERE bulk_id = @BulkId

-- or report an error
INSERT INTO EcLOG (ent_id, level, message) VALUES (@EntId, 1, 'unknown Unit of Measure') 
UPDATE EcENTITY SET comm_status = 9, processed2=GETDATE() WHERE bulk_id = @BulkId
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.besmart.software/erpc/data-interface-reference-manual/exporting-data-from-a-vault/reading-data-from-data-interface/workflow-sample.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
