Field Metadata Operations
Overview
Field metadata operations retrieve field definitions from TB_COST based on context (nuovo, modifica, visualizza). This enables dynamic form generation, validation, and UI rendering without hardcoding field names.
Endpoint
GET /api/v4/core/{DIM}/fields?source={SECURITY_AREA}¢er_dett={CONTEXT}
Parameters:
{DIM}: Dimension code (e.g., PRD, ORD)source: Security area (required)center_dett: Context for field visibility (required)
Context Values
| Context | Purpose | COD_ON_OFF Filter | Use Case |
|---|---|---|---|
nuovo | Create form | Fields with 'N' | Render create form |
modifica | Edit form | Fields with 'M' | Render edit form |
visualizza | View/list | Fields with 'L' or 'D' | Render detail view |
ricerca | Search form | Fields with 'R' or 'S' | Render search form |
Example Request
curl -X GET "https://coreservice.q01.io/api/v4/core/PRD/fields?source=productCreate¢er_dett=nuovo" \
-H "Authorization: Bearer eyJhbGc..."
Response Format
Structure: Object with field names as keys
{
"PRD_ID": {
"COD_COST": "PRD_ID",
"DESC_COST": "Product ID",
"TIPO_CAMPO": "int",
"COD_ON_OFF": "L,D",
"REQUIRED": true,
"COD_SEQUENZA": 10,
"INIT_VALUE": "",
"COD_UTENTE": 0
},
"XPRD01": {
"COD_COST": "XPRD01",
"DESC_COST": "Product Name",
"TIPO_CAMPO": "varchar(255)",
"COD_ON_OFF": "L,D,N,M,R",
"REQUIRED": true,
"COD_SEQUENZA": 20,
"INIT_VALUE": "",
"COD_UTENTE": 0
},
"XPRD02": {
"COD_COST": "XPRD02",
"DESC_COST": "Price",
"TIPO_CAMPO": "decimal(10,2)",
"COD_ON_OFF": "L,D,N,M",
"REQUIRED": true,
"COD_SEQUENZA": 30,
"INIT_VALUE": "0.00",
"COD_UTENTE": 0
}
}
Field Properties
| Property | Description | Example |
|---|---|---|
COD_COST | Field code/name | "XPRD01" |
DESC_COST | Human-readable label | "Product Name" |
TIPO_CAMPO | Data type from TB_TYPE_FIELDS | "varchar(255)", "int", "decimal(10,2)" |
COD_ON_OFF | Visibility flags | "L,D,N,M,R" |
REQUIRED | Is field required? | true, false |
COD_SEQUENZA | Display order | 10, 20, 30 |
INIT_VALUE | Default value | "", "0", "ACTIVE" |
COD_UTENTE | Minimum peso required | 0, 1, 2, 3 |
Use Case: Dynamic Form Generation
async function buildForm(dimension, context) {
// Fetch field metadata
const response = await fetch(
`/api/v4/core/${dimension}/fields?source=${context}Create¢er_dett=${context}`,
{
headers: { 'Authorization': `Bearer ${token}` }
}
);
const fields = await response.json();
// Generate form inputs
const form = document.createElement('form');
Object.values(fields)
.sort((a, b) => a.COD_SEQUENZA - b.COD_SEQUENZA)
.forEach(field => {
const input = createInput(field);
form.appendChild(input);
});
return form;
}
function createInput(field) {
const div = document.createElement('div');
// Label
const label = document.createElement('label');
label.textContent = field.DESC_COST;
if (field.REQUIRED) {
label.textContent += ' *';
}
div.appendChild(label);
// Input
let input;
if (field.TIPO_CAMPO.startsWith('varchar')) {
input = document.createElement('input');
input.type = 'text';
input.maxLength = extractLength(field.TIPO_CAMPO);
} else if (field.TIPO_CAMPO === 'int') {
input = document.createElement('input');
input.type = 'number';
input.step = 1;
} else if (field.TIPO_CAMPO.startsWith('decimal')) {
input = document.createElement('input');
input.type = 'number';
input.step = 0.01;
}
input.name = field.COD_COST;
input.required = field.REQUIRED;
input.value = field.INIT_VALUE;
div.appendChild(input);
return div;
}
Filtering by COD_ON_OFF
center_dett=nuovo (Create Form):
{
"XPRD01": { "COD_ON_OFF": "L,D,N,M,R" }, // ✅ Has N
"XPRD02": { "COD_ON_OFF": "L,D,N,M" }, // ✅ Has N
"XPRD15": { "COD_ON_OFF": "L,D,M" } // ❌ No N - excluded
}
center_dett=modifica (Edit Form):
{
"XPRD01": { "COD_ON_OFF": "L,D,N,M,R" }, // ✅ Has M
"XPRD02": { "COD_ON_OFF": "L,D,N,M" }, // ✅ Has M
"PRD_ID": { "COD_ON_OFF": "L,D" } // ❌ No M - excluded (read-only)
}
Summary
Field metadata operations enable:
- ✅ Dynamic form generation
- ✅ Client-side validation
- ✅ Context-aware field visibility
- ✅ Consistent UI across platforms
Next: Media Operations →